AnsweredAssumed Answered

Copy attributes from updated Table to Feature Class based on Unique ID

Question asked by JCrouch_ResponseGroup on May 2, 2017
Latest reply on Jun 6, 2017 by LarryAdgate

Hello All,

 

I am working on a script to copy attributes to their respective feature from a user edited DBF to a feature class. My organization creates sites in GIS, fills in a few key attributes, exports the attribute table to a DBF where our non-GIS users update the table in excel and then export to a tab delimited text file. Previously we have taken the updated DBF table, created a join, and manually used field calculator to copy the information back into the feature class but this takes quite a bit of time when we are dealing with 30-40 fields. 

 

I have written a basic script so far using search and update cursors using a value dictionary to relate the SiteID field (unique value) in the DBF to the SiteID field in the feature class however I can't get past how to make the script iterate through all of the rows and update the information. 

 

import os
import arcpy as ap

fc = r"Path\To\SitesFc"
dbf = r"Path\To\UpdatedTable.txt"

fcfieldList = [f.name for f in ap.ListFields(fc)]
dbffieldList = [f.name for f in ap.ListFields(dbf)]

valueDict = {r[0]:(r[1:]) for r in ap.da.SearchCursor(dbf, dbffieldList)}
            #[0] is SiteID field in DBF


with ap.da.UpdateCursor(fc, fcfieldList) as updateRows:
     for updateRow in updateRows:
          siteIDVal = updateRow[2] #[2] is SiteID field in FC
          if siteIDVal in valueDict:
                 # This is where I am lost. Not sure how to iterate through the fields

              
                    updateRows.updateRow(updateRow)

 

I would type out updateRow[x] = valueDict[SiteIDVal][x] but sometimes our field schemas change depending on the project and I want this to be a somewhat generic tool we can utilize.

 

Thaks in advance for the help!

Judson

Outcomes