[GIS] Updating a feature class

arcgis-10.2arcgis-desktopfield-calculatorpythontable

I am working on ArcGIS 10.2.1. I have a feature class containing more than 4000 records and a table having approximately 1000 records. Both feature class and table have some common fields however, with different values in them. Feature class is in ArcSDE geodatabase and table is in file geodatabase. We want to update feature class's fields with the values in table.

There are multiple fields (100 above). I was thinking of joining these two and then use field calculator but as records in feature class are more than the table and there are multiple fields which I want to update.

Is there any python script or tool I can use to update the feature class values from the table?

Best Answer

How about something like this:

import arcpy
mainTbl = r"C:\test.gdb\main"
lutTbl = r"C:\test.gdb\lut"
#Note the order of the fields in the search cursor has to coincide with field order in the update cursor
#Also assumes the matching fields are of compatibale types (exanple: can't insert string into integer)
lutDict = {r[0]:[i for i in r[1:]] for r in arcpy.da.SearchCursor(lutTbl, ["JOINFIELD","FIELD_A","FIELD_B","FIELD_C"])}
updateRows = arcpy.da.UpdateCursor(mainTbl, ["JOINFIELD","FIELD_A","FIELD_B","FIELD_C"])
for updateRow in updateRows:
    joinFieldVal = updateRow[0] 
    updateRow[1:] = lutDict[joinFieldVal]
    updateRows.updateRow(updateRow)
del updateRow, updateRows, lutDict
Related Question