I have a script to update a field in one feature class from a selected record in another feature class. This is done through looping through records in one feature class selecting appropriate the record in the other then reading the ID and updating the first feature class. I ran some tests on small subsets of the data and it worked fine. When i run across the full data set the MXD crashes (there are 30,000+/- records in the first feature class and 80,000 in the second). I am assuming this has something to do with memory, but I am not sure. Any help in solving this issue or improving the efficiency of the script (included below) is much appreciated. thanks.
import arcpy
cur = arcpy.UpdateCursor("layer_1")
for i in cur:
st=i.getValue("Street")
if st[-4:] == 'PKWY' or st[-4:] == 'EXPY':
pass
else:
qry = "Street = '"+st+"'"
arcpy.SelectLayerByAttribute_management("TAMED_BUF","NEW_SELECTION",qry)
arcpy.SelectLayerByLocation_management("TAMED_BUF","CONTAINS","layer_1",1,"SUBSET_SELECTION")
cur2=arcpy.SearchCursor("TAMED_BUF")
for row in cur2:
seg=row.getValue("SegmentID")
i.T_SegmentID = seg
cur.updateRow(i)
1 Answer 1
You may have better luck if you delete your cursor cur2 at the end of the else block. The lack of cleanup would explain the ArcMap crash, as memory loads up with abandoned cursor objects.
cur2=arcpy.SearchCursor("TAMED_BUF")
for row in cur2:
seg=row.getValue("SegmentID")
i.T_SegmentID = seg
cur.updateRow(i)
del row, cur2
As for ideas to help performance: have you tried the Join By Location on the two layers? If that connects the features for you, you could just do a join to the results and use the Join Fields tool to copy over attributes.
del cur,cur2,i,row