I am having an issue with the "select layer by location" tool in my ArcPy script, that may be due to a hidden memory error. Using one feature class with 281 polygons, I would like to select all of the possible bird ranges that overlap each polygon. There are ~12000 bird range polygons. My goal is a table with all of the 281 polygons and all the bird ranges associated with each one. Simply running the select by location tool runs into a memory error so I am attempting to iterate through each of the 281 shapes and export them to text file to later merge together.
The first 4 polygons accurately capture all of the intersecting polygons. Oddly, after that the script does not crash, but leaves out several hundred bird ranges for each of the 281 polygons. I know this by using the select by location tool on one feature in ArcMap and comparing the results.
Any ideas?
Maybe there is a different approach I haven't thought of.
def makeFeatureLayer():
env.workspace = pathlist[0] # Set initial workplace to file geodatabase
BirdData = "Joined_Study_Data"
tempBirdData = "BirdsDataTemp"
#selection is performed on a temporary layer
arcpy.MakeFeatureLayer_management(BirdData, tempBirdData)
print "Made temp layer:",tempBirdData
return tempBirdData
def selectionToText(temp_layer):
env.workspace = pathlist[0] # Set initial workplace to file geodatabase
FPUData = "FPU_proj"
cursor = arcpy.SearchCursor(FPUData)
for count,row in enumerate(cursor): # loop on each FPU feature
temp_layer = makeFeatureLayer() # make temp layer to avoid mem error
arcpy.SelectLayerByLocation_management (temp_layer, "INTERSECT",
#select based on geometry
row.SHAPE)
outname = pathlist[1]+"JoinSelection"+str(count)+".txt"
#export selection to text file, specifying fields of interest
arcpy.ExportXYv_stats(temp_layer,["SPCRECID","PRESENCE","ORIGIN",
"SEASONAL", "scientific_name",
"common_name", "rl_category"],
"COMMA", outname, "ADD_FIELD_NAMES")
print "Finished intersecting birds with FPU num:", str(count)
count+=1
def main():
temp_layer = makeFeatureLayer()
selectionToText(temp_layer)