Hello, I'm trying to make a simple script to loop through a list of properties (~700), selecting one at a time, and then select the intersecting features (there's 21 feature classes) and print them to screen. When i execute this script, it starts slowing down each time it goes to a new property. By property 15/700, it's already taking a few seconds for the "HAVE_THEIR_CENTRE_IN" select by location method. I feel there's something obvious I'm missing, or not resetting/cleaning up between each iteration in my loop.
Thank you for any help/advice.
import arcpy
import os
Property = r'C:\Boundaries.gdb\Property'
FeatureClasses = r'C:\FieldData.gdb'
properties = [row[0] for row in arcpy.da.SearchCursor(Property, 'NAME')]
arcpy.env.workspace = FeatureClasses
fcList = arcpy.ListFeatureClasses()
for prop in properties:
whereClause = "NAME = '"+prop+"'"
selectedProp = arcpy.management.SelectLayerByAttribute(Property, "NEW_SELECTION", whereClause)
print('property: '+prop)
for fc in fcList:
selectedFeatures = arcpy.management.SelectLayerByLocation(os.path.join(FeatureClasses, fc), "HAVE_THEIR_CENTER_IN", selectedProp)
print('fc: ' + str(fc) + ' and found "' + str(len(selectedFeatures)) + '"')