I have three columns (other than OID FID) in my shapefiles for river. And I want to update "from node" and "to node column"
Before update
from node to node gridcode
2 3 8
3 2 9
7 2 5
After update, I want "node column" to be same as "grid code" column, so I used field calculator in ArcGIS (from node = gridcode). My "from node" column has been changed to gridcode but not sure how to update "to node" column (that depends on values in “from node” column)
Below is the final result I want:
from node to node gridcode
8 9 8
9 8 9
5 8 5
<SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> node_values </SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">{}</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">
</SPAN><SPAN class="" style="color: #858c93; border: 0px; font-weight: inherit; font-size: inherit;"># build dictionary of values</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">
</SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit;">with</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> arcpy</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">da</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">.</SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-weight: inherit; font-size: inherit;">SearchCursor</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">fc</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">,</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">[</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">'FROM_NODE'</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">,</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">'GRID_CODE'</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">])</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit;">as</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> cursor</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">:
</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit;">for</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> row </SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit;">in</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> cursor</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">:
</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> old_node </SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> row</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">[</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">0</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">]
</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> new_node</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> row</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">[</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">1</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">]</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">
node_values</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">[</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">FROM_NODE</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">]</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> new_node
</SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit;">with</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> arcpy</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">da</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">.</SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-weight: inherit; font-size: inherit;">UpdateCursor</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">fc</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">,</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">[</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">'FROM_NODE'</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">,</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">'TO_NODE'</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">,</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">'GRID_CODE'</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">])</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit;">as</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> cursor</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">:</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">
</SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit;"> for</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> row </SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit;">in</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> cursor</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">:</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #858c93; border: 0px; font-weight: inherit; font-size: inherit;"># set fromnode to gridcode value</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">
row</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">[</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">0</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">]</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> row</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">[</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">2</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">]</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #858c93; border: 0px; font-weight: inherit; font-size: inherit;"># set tonode to new equivalent node</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">
to_node </SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> row</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">[</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">1</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">]</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"></SPAN><SPAN class="" style="color: #858c93; border: 0px; font-weight: inherit; font-size: inherit;"># I get an error here</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">
new_to_node </SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> node_values</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">[</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">TO_NODE</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">]</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">
row</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">[</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit;">1</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">]</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;"> new_to_node
cursor</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">updateRow</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit;">row)</SPAN><CODE><SPAN class="" style="color: #2b91af; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">Half</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;"> of the code </SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">is</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;"> working
</SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">import</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;"> arcpy</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;"> os</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;"> sys
</SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">from</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;"> arcpy </SPAN><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">import</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;"> env
fc</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">r</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">"C:/Users/wis/Desktop/python/fe/fea_c.shp"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">
</SPAN><SPAN class="" style="color: #858c93; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;"># instantiate empty dictionary</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">
</SPAN><SPAN class="" style="color: #858c93; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">#'FROM_NODE','GRID_CODE','TO_NODE' name of columns in my attribute table</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: inherit; margin: 0px;">
</SPAN>
The error is because row[1] or "to node" does not have all numbers that are in "from node" or "grid code" Because some values will repeat in t"no node" because one river can be connected to more than one rivers. However no repetition in "gridcode" and "from node" Any suggestions