2

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)
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
timpjohns
  • 339
  • 2
  • 10
  • 1
    Have you tried rebuilding the spatial index on the Shape file? – Nav Feb 16 '16 at 23:13
  • 2
    Have you thought about using the Intersect tool? – RHB Feb 16 '16 at 23:52
  • 1
    Probably not your issue, but you don't need to increment count, since you're getting count from the line "for count, row in enumerate(cursor):" anyway. – Tom Feb 17 '16 at 00:10
  • 1
    I doubt you're running into memory issues with so few features. However, you don't need the line "temp_layer = makeFeatureLayer()" within the selectionToText function. It's only recreating the layer that you already have. – Tom Feb 17 '16 at 00:37
  • 1
    Which version of ArcGIS do you use? Could you try the arcpy.da.SearchCursor()? It's supposed to be more performant than the built-in one. – GISGe Feb 17 '16 at 12:20
  • Thanks guys. I rebuilt the spatial index but unfortunately it didn't make a difference. @RHB, I am running the intersect tool now, I hadn't thought of that. Hopefully the results are what I'm looking for, its been running for about 4.5 hours and hasn't crashed. I'll try the arcpy.da.SearchCursor and iterating using the intersect tool if I don't get the results I'm looking for/it crashes. – timpjohns Feb 17 '16 at 19:41
  • Turns out the intersect tool did not work. Resulted in an empty shapefile. I finally found my answer here, for those of you who encounter a similar problem: http://gis.stackexchange.com/questions/25136/topology-or-out-of-memory-errors-with-large-dataset-intersects-and-spatial-joins – timpjohns Feb 19 '16 at 18:23

0 Answers0