2

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)
asked May 13, 2013 at 17:35
2
  • 1
    Make sure you are deleting your cursor objects at the end of the script: del cur,cur2,i,row Commented May 13, 2013 at 17:45
  • 3
    What error message (if any) are you getting? Also check your string manipulation logic, that will never evaluate to true. Commented May 13, 2013 at 19:14

1 Answer 1

5

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.

blah238
35.9k8 gold badges97 silver badges204 bronze badges
answered May 13, 2013 at 17:44
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.