Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def update_parcel_geometry(SWU_Parcels, Update_Parcels):
- #create parcel geometry dictionaries d1, d2
- cursor_fields = ['PID','SHAPE@','OID@']
- #dicts have index 0 as key and tuple of remainder as value
- arcpy.AddMessage('Reading SWU parcel geometries ...')
- with arcpy.da.SearchCursor(SWU_Parcels,cursor_fields) as cursor:
- d1 = {tup[0]:tup[1:] for tup in cursor}
- arcpy.AddMessage('Reading Update parcel geometries ...')
- with arcpy.da.SearchCursor(Update_Parcels,cursor_fields) as cursor:
- d2 = {tup[0]:tup[1:] for tup in cursor}
- #create dict of updated geoemetries
- # format { PID : SHAPE }
- update_dict = {t[0]: t[1][0] for t in d2.items() if t[0] in d1 and t[1][0] != d1[t[0]][0]}
- #create update cursor
- upd_fields = ['PID','SHAPE@','LAST_MODIFIED_BY','LAST_MODIFIED_DATE']
- with arcpy.da.UpdateCursor(SWU_Parcels,upd_fields) as upd_cursor:
- #commit updates
- for row in upd_cursor:
- if row[0] in update_dict:
- last_modified_by = 'ParcelScript'
- last_modified_date = datetime.datetime.now()
- PID = row[0]
- SHAPE = update_dict[row[0]]
- try:
- update = (PID,SHAPE,last_modified_by,last_modified_date)
- upd_cursor.updateRow(update)
- arcpy.AddMessage('Updating geometry for PID {}'.format(row[0]))
- except Exception as e:
- arcpy.AddMessage(e.args[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement