<?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: Select by Location Alternatives in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1177741#M64642</link>
    <description>&lt;P&gt;Your solutions work - thanks so much&amp;nbsp;@Anonymous User&amp;nbsp;. Meant to update this months ago!!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 May 2022 21:25:57 GMT</pubDate>
    <dc:creator>WillemVan_Riet1</dc:creator>
    <dc:date>2022-05-26T21:25:57Z</dc:date>
    <item>
      <title>Select by Location Alternatives</title>
      <link>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1139614#M63633</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking to find out which protected areas (output_PA_clip) fall into a planning unit (spatialjoin_fc), using the Select Layer by Location tool. If they meet this criteria, I would like them populate a field ("lock_out") to be "TRUE"&amp;nbsp; (this is for a Marxan type model)&lt;/P&gt;&lt;P&gt;Running this through arcpy creates individual "layers" (although not saved to the gdb) for each PU that meets this criteria. With run times of over 4 hours and the creation of 2000 + layers&lt;/P&gt;&lt;P&gt;Is there a way to "select" the feature based on my specific query but not have them create new layers each time?&lt;/P&gt;&lt;P&gt;Code below:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;values = [row[0] for row in arcpy.da.SearchCursor(spatialjoin_fc, "lock_out")]

with arcpy.da.InsertCursor(spatialjoin_fc, "lock_out") as cursor:
    for row in values:
        arcpy.SelectLayerByLocation_management(spatialjoin_fc, "have_their_center_in", output_PA_clip )
        row[0] == 'TRUE'
    cursor.insertRow(row)
del cursor&lt;/LI-CODE&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 22:36:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1139614#M63633</guid>
      <dc:creator>WillemVan_Riet1</dc:creator>
      <dc:date>2022-02-01T22:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Select by Location Alternatives</title>
      <link>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1139624#M63634</link>
      <description>&lt;P&gt;Not sure but it appears that a select by attributes to get all values would be simplest, then a single select by location which will use the subset of the first step.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="select_by_attributes.png" style="width: 280px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/32891i8377051872950EF4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="select_by_attributes.png" alt="select_by_attributes.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;doing it manually,&lt;/P&gt;&lt;P&gt;but once that set is selected all you are doing with the spatial join and assigning all those that meet the spatial condition the same value.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 22:55:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1139624#M63634</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-02-01T22:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Select by Location Alternatives</title>
      <link>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1139704#M63635</link>
      <description>&lt;P&gt;I think that you want an UpdateCursor to change the field value rather than inserting a new feature, which is what the InsertCursor does.&lt;/P&gt;&lt;P&gt;You mention that you want to "find out which protected areas (output_PA_clip) fall into a planning unit (spatialjoin_fc)..."&amp;nbsp; The way it is in your code, it is backwards. It's saying select if the spatial_join feature has ITS center in the output_PA_clip. You may be missing valid selections and also getting false positives. Do they just have to intersect or do they need to have their center within the planning unit?&amp;nbsp;&lt;/P&gt;&lt;P&gt;You may be able to get away with only one cursor, iterating over the selected items and updating them to true.&lt;/P&gt;&lt;P&gt;Edit: You also have == in your row[0] assignment that should be one =.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;selectedFeatures = arcpy.SelectLayerByLocation_management(spatialjoin_fc,  "INTERSECT", output_PA_clip)
with arcpy.da.UpdateCursor(selectedFeatures, ["lock_out"]) as cursor:
    for row in cursor:
        row[0] = 'TRUE'
        cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Feb 2022 03:36:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1139704#M63635</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-02-02T03:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Select by Location Alternatives</title>
      <link>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1140091#M63644</link>
      <description>&lt;P&gt;Thanks for your prompt and keen attention&amp;nbsp;@Anonymous User&amp;nbsp;&lt;/P&gt;&lt;P&gt;Will correct my code and update with my results.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Feb 2022 21:48:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1140091#M63644</guid>
      <dc:creator>WillemVan_Riet1</dc:creator>
      <dc:date>2022-02-02T21:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Select by Location Alternatives</title>
      <link>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1177741#M64642</link>
      <description>&lt;P&gt;Your solutions work - thanks so much&amp;nbsp;@Anonymous User&amp;nbsp;. Meant to update this months ago!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 21:25:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-location-alternatives/m-p/1177741#M64642</guid>
      <dc:creator>WillemVan_Riet1</dc:creator>
      <dc:date>2022-05-26T21:25:57Z</dc:date>
    </item>
  </channel>
</rss>

