Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)
share|improve this question
1  
Make sure you are deleting your cursor objects at the end of the script: del cur,cur2,i,row –  Jason May 13 '13 at 17:45
3  
What error message (if any) are you getting? Also check your string manipulation logic, that will never evaluate to true. –  blah238 May 13 '13 at 19:14
    
ah, thanks for cathing that. –  Hotpepper May 14 '13 at 15:08
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.