AnsweredAssumed Answered

Updating Line Geometry Based on Matching IDs

Question asked by jwilder@cpyone.com_CPYInc on Aug 20, 2020
Latest reply on Aug 20, 2020 by rvburton

Hi There. I am trying to update a Feature Class records with Polyline geometry (currently NULL) with the Polyline geometry of a Feature Class based on Matching ID fields. I can run this code without error, but it is not updating the Geometry at all and I'm not sure why that is. Any help is much appreciated. 

 

import arcpy

workspace = r'C:\test.gdb'
arcpy.env.workspace = workspace

# Feature Class of Lines with Geometry
FC_wGeom = r'C:\test.gdb\Lines'
wGeomFields = ['ObjectID', 'SHAPE@']

#Feature Class of Lines to inherit FC_wGeom's line shape
FC_woGeom = r'C:\test.gdb\LinesToBeUpdated'
woGeomFields = ['UniqueID', 'SHAPE@']

#start an edit session
edit = arcpy.da.Editor(workspace)

# Edit session is started without an undo/redo stack for versioned data
edit.startEditing(True, False)
print("start an edit session")
# Start an edit operation
edit.startOperation()

valueDict = {}

# Build dictionary of ObjectID and Line Geometry
for r in arcpy.da.SearchCursor(FC_wGeom, wGeomFields):
    if r[1] == None:
        pass
    else:
        valueDict[r[0]] = r[1:]
print(valueDict)

# Update FC_woGeom Feature Class with Geometry from FC_wGeom Feature Class IF OBJECTID and UniqueID match
with arcpy.da.UpdateCursor(FC_woGeom, woGeomFields) as updateRows:

    for updateRow in updateRows:
        keyValue = updateRow[0]
        print(keyValue)

        if keyValue in valueDict:
            updateRow[1] = valueDict[keyValue][0]
            print(valueDict[keyValue][0])
            updateRows.updateRow(updateRow)
            print("Updated {}".format(keyValue))

#Stop Editing
edit.stopOperation()
edit.stopEditing(True)
print("stop an edit session")

Outcomes