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.
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">as</SPAN> ap
fc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"Path\To\SitesFc"</SPAN>
dbf <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"Path\To\UpdatedTable.txt"</SPAN>
fcfieldList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f<SPAN class="punctuation token">.</SPAN>name <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> ap<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
dbffieldList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f<SPAN class="punctuation token">.</SPAN>name <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> ap<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>dbf<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
valueDict <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>r<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">(</SPAN>r<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> r <SPAN class="keyword token">in</SPAN> ap<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>dbf<SPAN class="punctuation token">,</SPAN> dbffieldList<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">#[0] is SiteID field in DBF</SPAN>
<SPAN class="keyword token">with</SPAN> ap<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> fcfieldList<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> updateRows<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> updateRow <SPAN class="keyword token">in</SPAN> updateRows<SPAN class="punctuation token">:</SPAN>
siteIDVal <SPAN class="operator token">=</SPAN> updateRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token">#[2] is SiteID field in FC</SPAN>
<SPAN class="keyword token">if</SPAN> siteIDVal <SPAN class="keyword token">in</SPAN> valueDict<SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># This is where I am lost. Not sure how to iterate through the fields</SPAN>
updateRows<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>updateRow<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I would type out updateRow = valueDict[SiteIDVal] 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