I am attempting to update utility feature classes with an update cursor. I have several layers I am practically doing this exact thing for and would really like to get it to work but I am stumped.
I have read a few other posts about this issue but they all seem to be older and without applicable solutions to what I am doing. I also found a post stating that this is a known bug/limitation of the update cursor, but is again from several years ago so I'm just not sure if this bug hasn't been fixed yet or if there is something else I am missing. There is no information on the UpdateCursor help documentation about the bug that I have come across.
I first tested all my code on copies of the sde layers that I put into a testing gdb and those all ran without error. However, now that I'm at the point of wanting to implement the script on my production data, I am getting the following error on line 32:
TypeError: cannot update the table
Any help or additional insight would be greatly appreciated!
Nicole
# WORKSPACE FOR EDIT SESSION
workspace = r"C:\Workspace\Default.sde"
# ASSIGN VARIABLE TO SUBDIVISION LAYER
outputSub = r"C:\org.sde\Subdivision"
# ASSIGN VARIABLE TO UTILITY LAYER
outputManhole = r"N:\Workspace\Default.sde\Manhole"
# SPATIAL JOIN SELECTION FC OF SUBDIVISIONS TO UTILITY FEATURES
arcpy.SpatialJoin_analysis(outputManhole, outputSub, outsubSJManhole, "JOIN_ONE_TO_MANY", "KEEP_ALL", "", "CLOSEST", 3000, "DIST")
# CONVERT MM/dd/yyyy TO yyyy ONLY
convertInstall = arcpy.ConvertTimeField_management(outsubSJManhole, "INSTALLDATE", "", "YEAR", "TEXT", "yyyy")
# ASSIGN VARIABLE TO OPEN EDIT SESSION
edit = arcpy.da.Editor(workspace)
# START EDIT SESSION
edit.startEditing(False, False)
# START EDIT OPERATION
edit.startOperation()
# TABLE JOIN OF ORIGINAL UTILITY LAYER TO CONVERTED DATETIME TABLE
InstallJoin = arcpy.AddJoin_management(outputManhole, "FACILITYID", convertInstall, "FACILITYID", "KEEP_ALL")
# ASSIGN VARIABLE TO DICTIONARY
# LIST COMPREHENSION TO FILL DICTIONARY USING SEARCH CURSOR
# KEY IS FACILITY ID TO MATCH RECORDS FROM SPATIAL JOIN
InstallDict = {r[0]: (r[1:]) for r in arcpy.da.SearchCursor(InstallJoin, ["Manhole.FACILITYID", "outsubSJManhole.YEAR"])}
# UPDATE CURSOR IN WITH STATEMENT
with arcpy.da.UpdateCursor(outputManhole, ["FACILITYID", "INSTALLDATE", "YEARBUILT"]) as cursor:
# FOR EVERY ROW BEING PULLED FROM TABLE
for row in cursor:
# IF 'INSTALLDATE' HAS A VALUE
if row[1] != None:
# KEY VALUE(FACILITY ID) IN DICTIONARY IS SAME AS FACILITY ID
FIELD IN UPDATE CURSOR FIELD
keyValue = row[0]
# IF KEY VALUE (FACILITY ID) IS IN THE DICTIONARY
if keyValue in InstallDict:
# 'YEARBUILT' IS EQUAL TO THE MATCHING DICTIONARY VALUE
BASED ON FACILITY ID
row[2] = InstallDict[keyValue][0]
# CALL TO UPDATE THE ROW WITH THE VALUE
cursor.updateRow(row)
# DELETE DICTIONARY
del InstallDict