AnsweredAssumed Answered

Arcpy - Select by location - iterate through gdb feature class and export to new fc

Question asked by brianmac1313 on Apr 5, 2020
Latest reply on Apr 6, 2020 by JB1234510

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.




# Import arcpy and set path to data
import arcpy
arcpy.env.workspace = r"C:\folder\Data.gdb\"

# Get the list of the featureclasses to process
fc_tables = arcpy.ListFeatureClasses()

for fc in fc_tables:
   arcpy.SelectLayerByLocation_management('fc', 'intersect', 'tile_index')
   arcpy.CopyFeatures_management(fc_tables, r"C:\Data.gdb\%Name%_selection")