Hello,
I need to update the distance field using the Pole_ID using Python script. From Pole_ID 0 to Pole_ID 1 and Pole_ID 1 to Pole_ID 2 and etc.
Kindly suggest me anyone.
More calculations are shown here, if you didn't find the suggestions correct
Geometry: Points in the field calculator
But, be aware that the attribute table is not guaranteed to be in PoleID order. Esp if you have done some editing.
Cumulative Distance
If you want distance from the first point then use cumulative distance:
repeat the steps from above
Pre-logic Script Code:
<SPAN class="string token">""</SPAN>" input shape field<SPAN class="punctuation token">:</SPAN> returns cumulative distance between points dist_cumu<SPAN class="punctuation token">(</SPAN>!Shape!<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#enter into the expression box"""</SPAN> x0 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0.0</SPAN><SPAN class="punctuation token">;</SPAN> y0 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0.0</SPAN><SPAN class="punctuation token">;</SPAN> distance <SPAN class="operator token">=</SPAN> <SPAN class="number token">0.0</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">dist_cumu</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">global</SPAN> x0<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">global</SPAN> y0<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">global</SPAN> distance x <SPAN class="operator token">=</SPAN> shape<SPAN class="punctuation token">.</SPAN>firstpoint<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">;</SPAN> y <SPAN class="operator token">=</SPAN> shape<SPAN class="punctuation token">.</SPAN>firstpoint<SPAN class="punctuation token">.</SPAN>Y <SPAN class="keyword token">if</SPAN> x0 <SPAN class="operator token">==</SPAN> <SPAN class="number token">0.0</SPAN> <SPAN class="operator token">and</SPAN> y0 <SPAN class="operator token">==</SPAN> <SPAN class="number token">0.0</SPAN><SPAN class="punctuation token">:</SPAN> x0 <SPAN class="operator token">=</SPAN> x<SPAN class="punctuation token">;</SPAN> y0 <SPAN class="operator token">=</SPAN> y distance <SPAN class="operator token">+=</SPAN> math<SPAN class="punctuation token">.</SPAN>sqrt<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>x <SPAN class="operator token">-</SPAN> x0<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">**</SPAN><SPAN class="number token">2</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>y <SPAN class="operator token">-</SPAN> y0<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">**</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> x0 <SPAN class="operator token">=</SPAN> x<SPAN class="punctuation token">;</SPAN> y0 <SPAN class="operator token">=</SPAN> y <SPAN class="keyword token">return</SPAN> distance <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>
calculation field =
dist_cumu<SPAN class="punctuation token">(</SPAN>!Shape!<SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
Same caveats as above.
NOTE:
if you have 3 or more points selected, then it will calculate the values with just the selection.
Inter-point distance
Do the following:
<SPAN class="string token">""</SPAN>" input shape field<SPAN class="punctuation token">:</SPAN> returns the distance between points <SPAN class="operator token">and</SPAN> its center dist_between<SPAN class="punctuation token">(</SPAN>!Shape!<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#enter into the expression box"""</SPAN> x0 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0.0</SPAN><SPAN class="punctuation token">;</SPAN> y0 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0.0</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">dist_between</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">global</SPAN> x0<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">global</SPAN> y0 x <SPAN class="operator token">=</SPAN> shape<SPAN class="punctuation token">.</SPAN>firstpoint<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">;</SPAN> y <SPAN class="operator token">=</SPAN> shape<SPAN class="punctuation token">.</SPAN>firstpoint<SPAN class="punctuation token">.</SPAN>Y <SPAN class="keyword token">if</SPAN> x0 <SPAN class="operator token">==</SPAN> <SPAN class="number token">0.0</SPAN> <SPAN class="operator token">and</SPAN> y0 <SPAN class="operator token">==</SPAN> <SPAN class="number token">0.0</SPAN><SPAN class="punctuation token">:</SPAN> x0 <SPAN class="operator token">=</SPAN> x<SPAN class="punctuation token">;</SPAN> y0 <SPAN class="operator token">=</SPAN> y distance <SPAN class="operator token">=</SPAN> math<SPAN class="punctuation token">.</SPAN>sqrt<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>x <SPAN class="operator token">-</SPAN> x0<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">**</SPAN><SPAN class="number token">2</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>y <SPAN class="operator token">-</SPAN> y0<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">**</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> x0 <SPAN class="operator token">=</SPAN> x<SPAN class="punctuation token">;</SPAN> y0 <SPAN class="operator token">=</SPAN> y <SPAN class="keyword token">return</SPAN> distance <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>
dist_between<SPAN class="punctuation token">(</SPAN>!Shape!<SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
where calculation field is your active field, it will show its name.
Make sure you have projected data and a double field or nothing will make sense.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.