1

I have multiple lines (lines) intersecting points (centroids) from which I want to extract landuse values and then write the extracted values to the lines as 'land1' and 'land2' values. I need to iterate through the line feature class in order to transfer the appropriate landuse values. My line layer is made up of 10's thousands of lines so the problem I have is that the select by location operation runs out of memory. I'm using ArcMap 10.0. I have tried processing the dataset in chunks but the problem persists. Why does my 'chunk' approach not work and how can I manage the memory use to avoid this sort of error?

Here is my code:

import arcpy

myfield = "LANDUSE"
obsList = []
obs = arcpy.SearchCursor("lines")
for row in obs:
    myid = row.OBJECTID
    obsList.append(myid)
del row
del obs

chunk = []
mycount = 0
for x in range(0,len(obsList),1000):
    mycount = mycount+1
    chunk = obsList[x:x+1000]
    chunkmax = chunk[len(chunk)-1]
    chunkmin = chunk[0]
    WhereClause = """"OBJECTID">={0} and "OBJECTID"<={1}""".format(chunkmin,chunkmax)
    sle = arcpy.SelectLayerByAttribute_management("lines", "NEW_SELECTION",WhereClause)
    cur = arcpy.UpdateCursor(sle)
    for row in cur:
        counter = 0
        geometry = row.getValue("SHAPE")
        fcs = arcpy.SelectLayerByLocation_management("centroids","INTERSECT",geometry)
        for feat in arcpy.SearchCursor(fcs):
            outval = str(feat.getValue(myfield))
            if counter == 0:
                row.LAND1 = outval
            upcur.updateRow(row)
            if counter == 1:
                row.LAND2 = outval
            upcur.updateRow(row)
            counter = counter +1
        del row
    del cur
    del sle
  • if you install and enable 64 bit Background Processing, you most likely will fix the out-of-memory error. – klewis Mar 10 '16 at 16:12
  • To my knowledge 64-bit background Geoprocessing was released with 10.1 service pack 1. As mentioned I'm stuck with 10.0. Is there anyway way to manage memory in arcpy/python so that it doesn't max out? – wunderkind Mar 11 '16 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.