Here's my issue. I am doing two things with arcpy:
1) I search a feature class using arcpy.da.SearchCursor()
and pull out a UID field and the geometry in WKB format for all polygons in the file, storing them in a dictionary.
2) I open a different, but similar feature class and use arcpy.da.UpdateCursor()
to update the geometries of polygons that have the same UID as above.
The problem is not all of the polygons are getting updated, even though the exact same UIDS exist in both feature classes. Some of them update just fine, but just under half do not.
import arcpy, time
updated_rid_dict = {}
updated_rows = 0
# Grab UIDs and geometries of updated regions
with arcpy.da.SearchCursor(good_geometry_shape, field_names=['RegionID', 'SHAPE@WKB']) as cursor:
for row in cursor:
updated_rid_dict[row[0]] = row[1]
print "{} updated regions found".format(len(updated_rid_dict)) # returns 594
# Open an edit session and attempt to find all the regions in updated_rid_dict
edit = arcpy.da.Editor([path to my data])
edit.startEditing(False, False)
edit.startOperation()
with arcpy.da.UpdateCursor(bad_geometry_shape, field_names=['RegionID', 'SHAPE@WKB']) as cursor:
for row in cursor:
# See if the feature is in the updated_rid_dict
if row[0] in updated_rid_dict:
updated_rows += 1
del updated_rid_dict[row[0]]
edit.stopOperation()
edit.stopEditing(True)
print "{} rows updated.".format(updated_rows) # Returns only 313
The code above doesn't even attempt to do an update. I can literally change "UpdateCursor" to "SearchCursor" and suddenly arcpy can find all the polygons in updated_rid_dict. I change it back to "UpdateCursor" and arcpy can only find some of the regions. I'm clueless as to what could be going wrong. Any ideas?
UPDATE: Using normal cursors does not fix the problem. Further testing shows that arcpy.da.UpdateCursor() iterates through every record up to OID 16781, then stops. Does UpdateCursor have some sort of limitations I'm not aware of? 16,781 records doesn't seem like that many to me.
del updated_rid_dict[row[0]]
part and report the count, please? If it turns to correct (i.e., 594), then @Hornbydd's first comment reflects your problem, RegionID may not be necessarily unique. Otherwise, you can test normal cursors (arcpy.SearchCursor, etc.) to see if the issue persists.