Monday 21 January 2019

arcgis desktop - Update value in one table (feature class) by coping it from another table. The match between table is done on values from another field


I have two tables (actually both are feature classes in filegeodatabase). They pretty much identical except. one is in lat/lon. second one is projected. both have field line_length and objectid. Second one has values in field line_length. how do I copy these values (based on objectid field match) from second table into the fist one.


The snippet of my code:


Part first. Create dictionary from second dataset. Copy values from second dataset into dictionary. value that I will be using for matching is goint to be key, the value I need to copy to my first dataset are going to be values. This part works ok.


my_dict = dict()
fc = r'H:\NetworkAnalyst\TopologyVer4\firetrials.gdb\ft_mb_afterIteration_lambert'
fields = ['OBJECTID', 'line_length']

with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
a_id = row[0]
b_len = row[1]
my_dict[a_id] = b_len

print "dictionary done"

Second part. Update field "line_length" in the first dataset with values from second dataset, which are now in dictionary. Match records by OBJECTID field.


rows = arcpy.UpdateCursor(r'H:\NetworkAnalyst\TopologyVer4\firetrials.gdb\ft_mb_afterIteration_lambert')

for key, value in my_dict:
match_value = key
update_value = value
for row in rows:
print match_value, update_value
if row.OBJECTID == match_value:
rows.setValue("line_lenght", update_value)

I am getting an error for line for key, value in my_dict:


Error is " TypeError: 'int' object is not iterable "



Any ideas?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...