<?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: Arcpy - Select by location - iterate through gdb feature class and export to new fc in Python Snippets Questions</title>
    <link>https://community.esri.com/t5/python-snippets-questions/arcpy-select-by-location-iterate-through-gdb/m-p/1176695#M699</link>
    <description>&lt;P&gt;I'm trying to do something similar, but instead of writing selected features to a layer, I want to deleted the selected features.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = r'K:/3DBasemaps/3DBasemaps/scratch_raw_points.gdb' 

# list feature classes in the workspace 
treeFeatureClasses = arcpy.ListFeatureClasses("", 'Point') 
print(treeFeatureClasses) 

for fc in treeFeatureClasses: 
    buildingPts = r'K:/3DBasemaps/3DBasemaps/scratch.gdb/' + fc 
    print(buildingPts) 
    arcpy.management.SelectLayerByLocation(fc,'ARE_IDENTICAL_TO', buildingPts) 
    print(fc + " County points were selected againts " + buildingPts + " points") 
    arcpy.management.DeleteFeatures(fc) 
    print(buildingPts + fc + "points deleted from " + fc)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But instead of deleting the selected features, it deletes all the features. &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 May 2022 01:52:24 GMT</pubDate>
    <dc:creator>Ian-Horn</dc:creator>
    <dc:date>2022-05-24T01:52:24Z</dc:date>
    <item>
      <title>Arcpy - Select by location - iterate through gdb feature class and export to new fc</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-select-by-location-iterate-through-gdb/m-p/774028#M134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I am trying to use arcpy to run a select by location and export the resulting selection (intersect) as a new feature class. I have set my workspace to the gdb containing the featureclasses I want to select by, and the features I want to select are a tile index feature class called 'tile_index'. The code will run but doesn't have any output. Any help would be great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# Import arcpy and set path to data&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"C:\folder\Data.gdb\"&lt;/SPAN&gt;


&lt;SPAN class="comment token"&gt;# Get the list of the featureclasses to process&lt;/SPAN&gt;
fc_tables &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListFeatureClasses&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; fc &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fc_tables&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByLocation_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'fc'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'intersect'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'tile_index'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; 
   arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;CopyFeatures_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc_tables&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"C:\Data.gdb\%Name%_selection"&lt;/SPAN&gt;&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:40:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-select-by-location-iterate-through-gdb/m-p/774028#M134</guid>
      <dc:creator>BrianMcNamara2</dc:creator>
      <dc:date>2021-12-12T08:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy - Select by location - iterate through gdb feature class and export to new fc</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-select-by-location-iterate-through-gdb/m-p/774029#M135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't know if I'm up to date but I think you have to use make feature layer infront of your select by location. Out of the help files:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"c:/data/mexico.gdb"&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# Make a layer and select cities which overlap the chihuahua polygon&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'cities'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'cities_lyr'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; 
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByLocation_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'cities_lyr'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'intersect'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'chihuahua'&lt;/SPAN&gt;&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;you should use:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;CODE&gt;arcpy&lt;SPAN class=""&gt;.&lt;/SPAN&gt;env&lt;SPAN class=""&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class=""&gt;=&lt;/SPAN&gt; r&lt;SPAN class=""&gt;"C:\folder\Data.gdb" and not&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;CODE&gt;arcpy&lt;SPAN class=""&gt;.&lt;/SPAN&gt;env&lt;SPAN class=""&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class=""&gt;=&lt;/SPAN&gt; r&lt;SPAN class=""&gt;"C:\folder\Data.gdb\"

&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;r&lt;SPAN class=""&gt;"C:\Data.gdb\%Name%_selection"&lt;/SPAN&gt;&lt;/CODE&gt; will not work in python code, 
you will need to create a unique name for your output file.&lt;/PRE&gt;&lt;CODE&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:40:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-select-by-location-iterate-through-gdb/m-p/774029#M135</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2021-12-12T08:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy - Select by location - iterate through gdb feature class and export to new fc</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-select-by-location-iterate-through-gdb/m-p/1176695#M699</link>
      <description>&lt;P&gt;I'm trying to do something similar, but instead of writing selected features to a layer, I want to deleted the selected features.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = r'K:/3DBasemaps/3DBasemaps/scratch_raw_points.gdb' 

# list feature classes in the workspace 
treeFeatureClasses = arcpy.ListFeatureClasses("", 'Point') 
print(treeFeatureClasses) 

for fc in treeFeatureClasses: 
    buildingPts = r'K:/3DBasemaps/3DBasemaps/scratch.gdb/' + fc 
    print(buildingPts) 
    arcpy.management.SelectLayerByLocation(fc,'ARE_IDENTICAL_TO', buildingPts) 
    print(fc + " County points were selected againts " + buildingPts + " points") 
    arcpy.management.DeleteFeatures(fc) 
    print(buildingPts + fc + "points deleted from " + fc)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But instead of deleting the selected features, it deletes all the features. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 01:52:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-select-by-location-iterate-through-gdb/m-p/1176695#M699</guid>
      <dc:creator>Ian-Horn</dc:creator>
      <dc:date>2022-05-24T01:52:24Z</dc:date>
    </item>
  </channel>
</rss>

