Hello everyone, I am having trouble when trying to automate the process of select-by-location and copy-features in python. My codes looks like below: The logic seems to be right but once it runs, it runs forever which definitely exceeds the time I ran in Arcpro. Any ideas would be appreciated, thank you!
import arcpy
from arcpy import env
env.workspace = "D:/Backup/shapefile/NE_validation"
outworkspace = "D:/Backup/shapefile/NE_validation"
NEEEfishnet = "D:/Backup/shapefile/NE_validation/NE_validation.gdb/NEEE_NewEngland_fishnet"
shplist = arcpy.ListFeatureClasses("*Point*")
for shp in shplist:
# select by location
arcpy.management.SelectLayerByLocation(NEEEfishnet, "INTERSECT", shp, None, "NEW_SELECTION", "NOT_INVERT")
# export selected features (use copy features tool)
outfeature = outworkspace + "/" + NEEEfishnet[52:75] + shp[37:40] + ".shp"
arcpy.management.CopyFeatures(NEEEfishnet, outfeature, '', None, None, None)
# clear selection
arcpy.SelectLayerByAttribute_management(NEEEfishnet, "CLEAR_SELECTION")
Update: I change the code to adopt two more functions: make feature layer and save layer to file. The code runs but it does not produce shapefile that is openable. The error message says below. I am going to stop updating, and maybe someone someday will find a solution to this problem...
