<?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 Select Current Feature in a Search Cursor Loop in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/749508#M57913</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am looping through a shapefile using a Search Cursor loop, and need to create a specific operation.&amp;nbsp; I need to select the current feature that the loop is on, and then run a select by location operation on that selected feature.&amp;nbsp; Once my operation is done, I then need to move onto the next feature in the loop.&amp;nbsp; Here is my current code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;fc = r"V:/Metro/STOP_CONSOLIDATION/STOPS.gdb/Stop_Database_Points"&lt;BR /&gt;fields = ["BEGINSTOPI", "METRO", "GpsLongitu", "GpsLatitud"]&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(fc, fields) as cursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt; arcpy.SelectLayerByLocation_management(point_lyr, overlap_type="WITHIN_A_DISTANCE", select_features=point_lyr, search_distance="1320 Feet", selection_type="NEW_SELECTION", invert_spatial_relationship="#")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ps, as a side note, how do I add code tags to the new board?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 30 Apr 2015 15:40:24 GMT</pubDate>
    <dc:creator>ClintonCooper1</dc:creator>
    <dc:date>2015-04-30T15:40:24Z</dc:date>
    <item>
      <title>Select Current Feature in a Search Cursor Loop</title>
      <link>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/749508#M57913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am looping through a shapefile using a Search Cursor loop, and need to create a specific operation.&amp;nbsp; I need to select the current feature that the loop is on, and then run a select by location operation on that selected feature.&amp;nbsp; Once my operation is done, I then need to move onto the next feature in the loop.&amp;nbsp; Here is my current code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;fc = r"V:/Metro/STOP_CONSOLIDATION/STOPS.gdb/Stop_Database_Points"&lt;BR /&gt;fields = ["BEGINSTOPI", "METRO", "GpsLongitu", "GpsLatitud"]&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(fc, fields) as cursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt; arcpy.SelectLayerByLocation_management(point_lyr, overlap_type="WITHIN_A_DISTANCE", select_features=point_lyr, search_distance="1320 Feet", selection_type="NEW_SELECTION", invert_spatial_relationship="#")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ps, as a side note, how do I add code tags to the new board?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 15:40:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/749508#M57913</guid>
      <dc:creator>ClintonCooper1</dc:creator>
      <dc:date>2015-04-30T15:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: Select Current Feature in a Search Cursor Loop</title>
      <link>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/749509#M57914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;See &lt;A _jive_internal="true" href="https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet"&gt;here&lt;/A&gt; for Posting Code Blocks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 16:30:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/749509#M57914</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-04-30T16:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: Select Current Feature in a Search Cursor Loop</title>
      <link>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/1022663#M59767</link>
      <description>&lt;P&gt;Hi!&amp;nbsp; I am hoping to achieve this exact thing.&amp;nbsp; Did you ever figure out how to do it,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/162552"&gt;@ClintonCooper1&lt;/a&gt;&amp;nbsp;?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 18:35:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/1022663#M59767</guid>
      <dc:creator>AllenDailey1</dc:creator>
      <dc:date>2021-02-02T18:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Select Current Feature in a Search Cursor Loop</title>
      <link>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/1022734#M59768</link>
      <description>&lt;P&gt;You need to get the row ID or OBJECTID from the cursor, then use it in a SQL query in the selectlayerbyattribute to select the feature.&amp;nbsp; Then use the selected feature in the select by location.&amp;nbsp; Something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fc = r"V:/Metro/STOP_CONSOLIDATION/STOPS.gdb/Stop_Database_Points"
fields = ["OBJECTID", "BEGINSTOPI", "METRO", "GpsLongitu", "GpsLatitud"]

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:
        whereclause = """OBJECTID = {}""".format(row[0])
        selectLyr = arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", whereclause)
        intersectLyr = arcpy.SelectLayerByLocation_management(point_lyr, overlap_type="WITHIN_A_DISTANCE", select_features=selectLyr,
                                       search_distance="1320 Feet", selection_type="NEW_SELECTION",
                                       invert_spatial_relationship="#")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;then do something with the selected by location layer.&amp;nbsp; You'll have to update the code to match your field names.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 20:32:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/1022734#M59768</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-02T20:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Select Current Feature in a Search Cursor Loop</title>
      <link>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/1022816#M59769</link>
      <description>&lt;P&gt;Although this approach will definitely work, I think a cleaner approach would be to retrieve the geometry in question and pass that to Select Layer By Location since that tool can accept ArcPy geometry objects as the selecting layer.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fc = r"V:/Metro/STOP_CONSOLIDATION/STOPS.gdb/Stop_Database_Points"
fields = ["SHAPE@", "OBJECTID", "BEGINSTOPI", "METRO", "GpsLongitu", "GpsLatitud"]

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:
        shp = row[0]
        intersectLyr = arcpy.SelectLayerByLocation_management(point_lyr, overlap_type="WITHIN_A_DISTANCE", select_features=shp,
                                       search_distance="1320 Feet", selection_type="NEW_SELECTION",
                                       invert_spatial_relationship="#")&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 02 Feb 2021 23:11:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/1022816#M59769</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-02-02T23:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Select Current Feature in a Search Cursor Loop</title>
      <link>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/1022826#M59770</link>
      <description>&lt;P&gt;That is pretty legit. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 23:30:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/1022826#M59770</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-02T23:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Select Current Feature in a Search Cursor Loop</title>
      <link>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/1022848#M59771</link>
      <description>&lt;P&gt;Thank you very much, JeffK and JoshuaBixby, for your helpful replies!!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 00:16:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-current-feature-in-a-search-cursor-loop/m-p/1022848#M59771</guid>
      <dc:creator>AllenDailey1</dc:creator>
      <dc:date>2021-02-03T00:16:10Z</dc:date>
    </item>
  </channel>
</rss>

