I have a feature class (FC) which has fields with associated look up tables. The look up tables have columns (CODE and DESCRIPTION). The FC table fields are filled with CODE values. I want to replace them with DESCRIPTION value.
The code below does that but does not update the feature class. I have not used arcpy cursor. I need help on where and how to use arcpy update cursor in the code to affect changes in the FC table
the code :
import arcpy arcpy.env.workspace = "C:/..." fc = "K" fields = ["STATUS", "COLOR", "TYP", "MATERIAL", "FUNCTION", "POWER", "LOSS"] # creating list with field values l = [[row.getValue(field) for row in arcpy.SearchCursor(fc)] for field in fields ] # list of look up tables tbs = ["LK_STATUS", "LK_COLOR", "LK_TYP", "LK_MATERIAL", "LK_FUNCTION", "LK_POWER", "LK_LOSS"] #creating dictionary for key-value pair as CODE
ESCRIPTION dicts = [] for tb in tbs: with arcpy.da.SearchCursor(tb,["CODE", "DESCRIPTION_G"]) as srows: dicts.append(dict([srow[0], srow[1]] for srow in srows)) lookup = dict(enumerate(dicts)) def match( l, lookup): for i in l: for k,v in lookup.items(): if i == k: i = v else: i = i print i for i in range(len(l)): match(l, lookup)
أكثر...
The code below does that but does not update the feature class. I have not used arcpy cursor. I need help on where and how to use arcpy update cursor in the code to affect changes in the FC table
the code :
import arcpy arcpy.env.workspace = "C:/..." fc = "K" fields = ["STATUS", "COLOR", "TYP", "MATERIAL", "FUNCTION", "POWER", "LOSS"] # creating list with field values l = [[row.getValue(field) for row in arcpy.SearchCursor(fc)] for field in fields ] # list of look up tables tbs = ["LK_STATUS", "LK_COLOR", "LK_TYP", "LK_MATERIAL", "LK_FUNCTION", "LK_POWER", "LK_LOSS"] #creating dictionary for key-value pair as CODE
أكثر...