Hi,
I have been pointed to a script for calculating the distance between consecutive points and now I need a script or some other way for calculating the bearing (N, NE, NW, etc) between the same points.
Thanks for your help,
Bob
Hi Bob
If you have your angles then you need to test they are within +/- 11.25 degrees of these azimuth breaks:
N:0
NNE:22.5
NE:45
ENE:67.5
... and so on.
BTW, the values are easy to calculate (obviously) but in a shameless plug for Esri's geocoding open file:///C:/Program%20Files%20(x86)/ArcGIS/Desktop10.4/Locators/USAddress.lot.xml in Firefox and navigate to the Spatial Operators elements - very few people know you can prepend spatial operators to street addresses and geocode "off road".
Bruce,
I have calculated azimuths already, what I need now is a script for
converting the numbers to text--N, NE, NW etc. I can't seem to find just
what I want so far. I've been looking at if/then statements in both VB and
Python.
Thanks,
Dan,
With the scripts you sent earlier I was able to calculate azimuths. What I
need now is a script for converting the numbers to N, NE, NW etc. I can't
seem to find just what I want so far. I've been looking at if/then
statements in both VB and Python.
On Tue, Sep 20, 2016 at 8:19 PM, Chris Donohue, GISP <geonet@esri.com>
there are two different field calculator expressions in this link
/blogs/dan_patterson/2016/09/01/distance-calculations-using-the-field-calculator
<SPAN class="string token">""" azimuth_to(shape, from_x, from_y) input: shape field, from_x, from_y returns: angle between 0 and <360 between a specified point and others expression: azimuth_to(!Shape!, from_x, from_y) """</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">azimuth_to</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">,</SPAN> from_x<SPAN class="punctuation token">,</SPAN> from_y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> radian <SPAN class="operator token">=</SPAN> math<SPAN class="punctuation token">.</SPAN>atan<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">.</SPAN>centroid<SPAN class="punctuation token">.</SPAN>X <SPAN class="operator token">-</SPAN> from_x<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">/</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">.</SPAN>centroid<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">-</SPAN> from_y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> degrees <SPAN class="operator token">=</SPAN> math<SPAN class="punctuation token">.</SPAN>degrees<SPAN class="punctuation token">(</SPAN>radian<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> degrees <SPAN class="operator token"><</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> degrees <SPAN class="operator token">+</SPAN> <SPAN class="number token">360.0</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> degrees<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>
Expression
azimuth_to<SPAN class="punctuation token">(</SPAN>!Shape!<SPAN class="punctuation token">,</SPAN>from_x<SPAN class="punctuation token">,</SPAN> from_y<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Or this one
<SPAN class="string token">""" angle_between(shape) input: shape field returns: angle between successive points, NE +ve 0 to 90, NW +ve 90 to 180, SE -ve <0 to -90, SW -ve <-90 to -180 expression: angle_between(!Shape!) """</SPAN> x0 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0.0</SPAN> y0 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0.0</SPAN> angle <SPAN class="operator token">=</SPAN> <SPAN class="number token">0.0</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">angle_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="keyword token">global</SPAN> y0 x <SPAN class="operator token">=</SPAN> shape<SPAN class="punctuation token">.</SPAN>centroid<SPAN class="punctuation token">.</SPAN>X y <SPAN class="operator token">=</SPAN> shape<SPAN class="punctuation token">.</SPAN>centroid<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 y0 <SPAN class="operator token">=</SPAN> y <SPAN class="keyword token">return</SPAN> <SPAN class="number token">0.0</SPAN> radian <SPAN class="operator token">=</SPAN> math<SPAN class="punctuation token">.</SPAN>atan2<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">.</SPAN>centroid<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">-</SPAN> y0<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">.</SPAN>centroid<SPAN class="punctuation token">.</SPAN>X <SPAN class="operator token">-</SPAN> x0<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> angle <SPAN class="operator token">=</SPAN> math<SPAN class="punctuation token">.</SPAN>degrees<SPAN class="punctuation token">(</SPAN>radian<SPAN class="punctuation token">)</SPAN> x0 <SPAN class="operator token">=</SPAN> x y0 <SPAN class="operator token">=</SPAN> y <SPAN class="keyword token">return</SPAN> angle <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></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
angle_between<SPAN class="punctuation token">(</SPAN>!Shape!<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
You can mess around with them to get what you want in terms in terms of inputs and outputs.
Here is a function:
# North azimuth bearing of a line segment (degrees)def NorthAzimuth(x1,y1,x2,y2): degBearing = math.degrees(math.atan2((x2 - x1),(y2 - y1))) if (degBearing < 0): degBearing += 360.0 return degBearing
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.