ljvasil

Code crashed after 23,000 points processed

Discussion created by ljvasil on Feb 2, 2012
Latest reply on Feb 2, 2012 by ljvasil
Hi all,

I have this weird error that happens after a very large number of points processed using a cellular automata code for land use change.  It varies in the number of points before it crashes, but it always gives me the error "row not defined".  What I don't get it is if the code ran without this error for 22,999, why would it decide that this point is where row is not defined.  I've checked the land use point file...nothing unusual about the location of the point.  The psuedo code if you need it is:

describe the input layer...point land use cover file
make feature layer active
set up update cursor, uc
look at each point in uc
get FID value
put in sequential order
select points within 45 meters of processing point
get grid codes values (ranked priority of land uses)
put in list
get large value in list
count large value in list
if large value > value in processing point and count large value is > 4, processing point grid code is changed to large value

Here's the actual code:
import sys, string, os, arcpy

#check out necessary licenses
arcpy.CheckOutExtension("spatial")

ifc = sys.argv[1]

ily = "Input Layer"

desc = arcpy.Describe(ifc)

arcpy.MakeFeatureLayer_management(ifc,ily, "", "", "")
oid = desc.OIDFieldName

uc = arcpy.UpdateCursor(ifc)
line = uc.next()

for line in uc:    
    ci = line.getValue(oid)
    arcpy.AddMessage("The current FID value is " + str(ci))
    fi = line.getValue("GRID_CODE")
    arcpy.AddMessage("The current GridCode value is " + str(fi))
    sql = oid + " = " + str(ci)
    arcpy.SelectLayerByAttribute_management(ily,"NEW_SELECTION",sql)
    result = arcpy.SelectLayerByLocation_management(ily, "WITHIN_A_DISTANCE", ily, "45 meters", "NEW_SELECTION")
    sc = arcpy.SearchCursor(result)
    gridList = []
    OIDList = []
    for row in sc:
        item = row.getValue("GRID_CODE")
        id = row.getValue(oid)
        OIDList.append(id)
        gridList.append(item)
                        
    del row
    del sc
    
    gridList.sort()
    arcpy.AddMessage(gridList)
    LR_Value = gridList[-1]
    if LR_Value < 6:
        tie_LR = gridList.count(LR_Value)
        arcpy.AddMessage("The large value in list is " + str(LR_Value))
        arcpy.AddMessage("This is the tie value " + str(tie_LR))
        if tie_LR >= 4 and LR_Value > fi:
            fi = LR_Value  
            line.setValue("GRID_CODE",fi)  
            uc.updateRow(line)
            arcpy.AddMessage("This is the updated value " + str(fi))
            
del line
del uc


Any help would be appreciated...I'm stumped!

Thanks!

Outcomes