Update values in fields from look up table

المشرف العام

Administrator
طاقم الإدارة
I have a feature class with several attributes/fields. Some of these fields have associated look up tables (arcgis tables). These tables have two columns, CODE and DESCRIPTION. Currently fields in feature class have values as CODE. I want to update the field values with DESCRIPTION corresponding to its CODE as per look up table. This is required to be done many times so i want to write function which can be reused.

So far what i have done:

I am using arcpy. I have created dictionaries for each lookup table with CODE, DESCRIPTION as key, value pairs and i have copied all the fields into python list. The list has sub-list which contains each field. Below is a simplified code for sake of example

#dictionaries for each lookup tablelookup = { 0:{1003 : "unknown", 1006:"tile", 1005: "wood"}, #lookup table 1 1:{1001: "blue", 1002: "red", 1005:"green", 1006:"brown", 1007:"colorless"} # lookup table 2 } for k,v in lookup.items(): print k,v #list with fields values l = [ [1006, 1004, 1006, 1006, 1006, 1005, 1004, 1006], #field 1 [1005, 1006, 1007, 1005, 1004, 1005, 1001, 1002] #field 2 ] print ("----") def match( l, lookup): for i in l: for k,v in lookup.items(): if i == k: i = v else: i = i print i row = range(len(l[0]))for i in range(len(l)): row = match(l, lookup) print "***"this works fine. it replaces the values correctly for two lookup table for two fields each. But in actual scenario do not have lookup tables for all fields. Somehow i must program so that it knows which lookup table is for which field. May be i can use associated fieldindex but how to get it ?

if anything is unclear do ask me.

Thanks



أكثر...
 
أعلى