<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Adding to a Selection in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486159#M37934</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Now I get it!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Sep 2017 16:30:25 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2017-09-08T16:30:25Z</dc:date>
    <item>
      <title>Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486149#M37924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Python hack (at best) here....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to base a selection on an already selected record in a layer, and can't quite seem to crack that nut. &amp;nbsp;Here is the pseudo code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select a record &amp;nbsp;'&amp;nbsp;in this case a point&lt;/P&gt;&lt;P&gt;Extract the FullStreet attribute value &amp;nbsp;' it'll be something like S MAIN ST&lt;/P&gt;&lt;P&gt;Add to the selection all other points that have that same FullStreet field value &amp;nbsp; 'seems like a fairly simple operation&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've been trying to do that using an arcpy.SearchCursor &amp;nbsp;within the arcpy window :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; cursor = arcpy.SearchCursor("apLayer")&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; for row in cursor:&lt;BR /&gt;... street = row.FullStreet&lt;BR /&gt;... arcpy.SelectLayerByAttribute_management ("apLayer","ADD_TO_SELECTION","FullStreet = 'street'")&lt;BR /&gt;... &lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;This runs with no errors but only ends up with the originally selected point as being selected. &amp;nbsp;(See attached)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Questions: &amp;nbsp;is this a case of newbie syntax error?&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; is there a better approach to do what I intend to do? &amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2017 17:54:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486149#M37924</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2017-09-07T17:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486150#M37925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you creating a feature layer first?&amp;nbsp; Look at the sample for a subset of a selection in the help&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/select-layer-by-attribute.htm" title="http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/select-layer-by-attribute.htm"&gt;Select Layer By Attribute—Help | ArcGIS for Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It doesn't use a cursor, but might give you some other help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2017 18:01:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486150#M37925</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2017-09-07T18:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486151#M37926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, I'm working against a layer which is another source of bewilderment to me. &amp;nbsp;The documentation says that&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;arcpy.SelectLayerByAttribute_management&lt;SPAN&gt;&amp;nbsp;only works &amp;nbsp;against layers and not feature classes. &amp;nbsp;However, I've run it against both (outside of a cursor) and had it work when I hard code the FullStreet value like this:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management ("apLayer","ADD_TO_SELECTION","FullStreet = 'S BOX ELDER ST'")&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2017 18:22:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486151#M37926</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2017-09-07T18:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486152#M37927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;"FullStreet = 'street'" looks for the literal string 'street', and since you probably don't have any records where the value is 'street', nothing gets added.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;You need to substitute the variable value into your query, which gets a little complicated with the quotes. Basically, it should be something like: "FullStreet = '" + street + "'" (but you may have to play around with the quoting situation).&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2017 18:50:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486152#M37927</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2017-09-07T18:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486153#M37928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And using&amp;nbsp; &lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-functions/addfielddelimiters.htm" title="http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-functions/addfielddelimiters.htm"&gt;AddFieldDelimiters—Help | ArcGIS for Desktop&lt;/A&gt; might help.&amp;nbsp; Also,&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/10.3/analyze/python/specifying-a-query.htm" title="http://desktop.arcgis.com/en/arcmap/10.3/analyze/python/specifying-a-query.htm"&gt;Specifying a query in Python—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2017 18:57:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486153#M37928</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2017-09-07T18:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486154#M37929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/19932"&gt;Darren Wiens&lt;/A&gt;‌ &amp;amp; &lt;A href="https://community.esri.com/migrated-users/2691"&gt;Rebecca Strauch, GISP&lt;/A&gt;‌ &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Darren and Rebecca- &amp;nbsp;Thank you both for your suggestions; &amp;nbsp;I got dragged into an endless meeting that finally did end and I haven't had a chance yet to chase down the quotes thing and the links you two provided. &amp;nbsp;Thanks in advance!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2017 21:57:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486154#M37929</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2017-09-07T21:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486155#M37930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When I run Select Layer By Attribute directly against a feature class, it generates an error:&amp;nbsp; "Parameters are not valid. The value cannot be a feature class."&amp;nbsp; Can you elaborate more on how you run it directly against a feature class?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2017 22:54:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486155#M37930</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-09-07T22:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486156#M37931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are messing with the selection on a layer&amp;nbsp;&lt;EM&gt;while it's open&lt;/EM&gt;. Even if you get the expression right I think&amp;nbsp;it may not work right.&lt;/P&gt;&lt;P&gt;I think the following will do what you want and seems wiser to me. (Also, arcpy.da.SearchCursor is much faster than the old flavor)&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# collect street names from selected points &lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# (works with one or more selected features)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"aplayer"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"FullStreet"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; streets &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# cursor closes when we leave the with block&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# convert to a string list for our select expression&lt;/SPAN&gt;
street_list &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;","&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"'{}'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;s&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; s &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; streets&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; 
&lt;SPAN class="comment token"&gt;# street_list will look like: "'E MAIN', 'W MAIN'"&lt;/SPAN&gt;
where &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"FullStreet IN ({})"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;street_list&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# add all points with these street names to the selected set&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByAttribute_management &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"apLayer"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;"ADD_TO_SELECTION"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:25:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486156#M37931</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T21:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486157#M37932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/3420"&gt;Joshua Bixby&lt;/A&gt;‌ &lt;A href="https://community.esri.com/migrated-users/3355"&gt;Curtis Price&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Joshua- &amp;nbsp;all I can say is it's probably dumb luck that I can get it to work directly upon a feature class. &amp;nbsp;However, it may be (if I understand Curtis' reply) the fact that I'm working in the python window in an ArcMap session with the &lt;EM&gt;feature class right there and available for reading&lt;/EM&gt;. &amp;nbsp;See attached screen cap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Curtis- &amp;nbsp;thanks for your insight. &amp;nbsp;Let me mess with your suggested code. &amp;nbsp;I kind of figured that the arcpy.da cursor would show up in the conversation sooner or later; &amp;nbsp;I'll work with it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;eta: &amp;nbsp;the Curtis code works quite nicely. &amp;nbsp;See attached success.png &amp;nbsp;(For good practice I'm hitting a layer instead of the feature class itself and using the arcpy.da cursor.)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Sep 2017 15:35:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486157#M37932</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2017-09-08T15:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486158#M37933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Because you're running this in ArcMap, even though the underlying dataset is a &lt;EM&gt;feature class&lt;/EM&gt;, you are referencing the &lt;EM&gt;feature layer&lt;/EM&gt;. If you reference the feature class by including the full path rather than the feature layer name, you should get the error Joshua mentions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Sep 2017 16:20:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486158#M37933</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2017-09-08T16:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to a Selection</title>
      <link>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486159#M37934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Now I get it!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Sep 2017 16:30:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-to-a-selection/m-p/486159#M37934</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2017-09-08T16:30:25Z</dc:date>
    </item>
  </channel>
</rss>

