<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to calculate the angle of a line respect to the North in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1212337#M26472</link>
    <description>&lt;P&gt;Thank you! I'm indeed calculating the geographic angle and your solution works well, but just in some cases it is odd. For example, for the lines in the image below the dashed line's angle results to be 177° and the one for the solid line is 354°, so they are both wrong... could it be due to the sense in which I drew the lines?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They should be : dashed line around 100° and solid line around 75°&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CeciliaMartinelli_1-1663149603287.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51138i5AF07A4F1128F83B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CeciliaMartinelli_1-1663149603287.png" alt="CeciliaMartinelli_1-1663149603287.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Sep 2022 10:01:14 GMT</pubDate>
    <dc:creator>CeciliaMartinelli</dc:creator>
    <dc:date>2022-09-14T10:01:14Z</dc:date>
    <item>
      <title>How to calculate the angle of a line respect to the North</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1211983#M26464</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I would like to calculate the angle of the lines in the image respect to the North. Is there a tool that can do that? and eventually put the output in the Attributes table. I know that these lines aren't perfectly straight but I need the average&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CeciliaMartinelli_0-1663077198866.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51023i3726F6C843A964F2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CeciliaMartinelli_0-1663077198866.png" alt="CeciliaMartinelli_0-1663077198866.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm using ArcGis Pro 3.0.0&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 13:57:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1211983#M26464</guid>
      <dc:creator>CeciliaMartinelli</dc:creator>
      <dc:date>2022-09-13T13:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the angle of a line respect to the North</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1212005#M26466</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;STRIKE&gt;I don't think there is a tool that does that out of the box&lt;/STRIKE&gt; (edit: nevermind, see above). But you can easily calculate the value with &lt;A href="https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/calculate-field.htm" target="_blank" rel="noopener"&gt;Calculate Field&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;angle of the lines in the image respect to the North&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Do you mean the geographic angle (North=0°, East=90°)? If so, use this Arcade expression in the tool:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get a list of line parts
var paths = Geometry($feature).paths
// for each part, loop through each segment and get its angle (arithmetic angle -&amp;gt; East=0°, North=90°)
var angles = []
for(var p in paths) {
    var count_p = Count(paths[p])
    for(var q = 1; q &amp;lt; count_p; q ++) {
        var a = Angle(paths[p][q], paths[p][q-1])
        Push(angles, a)
    }
}
// get the mean arithmetic angle
var arith_angle = Mean(angles)
// convert to geographic and return
return (450 - arith_angle) % 360&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1663080583343.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51027iE061B5B3D143A8EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1663080583343.png" alt="JohannesLindner_0-1663080583343.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or do you mean the arithmetic angle (rotating counter-clockwise) but with North = 0°? Then use this expression:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get a list of line parts
var paths = Geometry($feature).paths
// for each part, loop through each segment and get its angle (arithmetic angle -&amp;gt; East=0°, North=90°)
var angles = []
for(var p in paths) {
    var count_p = Count(paths[p])
    for(var q = 1; q &amp;lt; count_p; q ++) {
        var a = Angle(paths[p][q], paths[p][q-1])
        Push(angles, a)
    }
}
// get the mean arithmetic angle
var arith_angle = Mean(angles)
// rotate so that North = 0°
var north_arith_angle = arith_angle - 90
return north_arith_angle + IIF(north_arith_angle &amp;lt; 0, 180, 0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1663081411842.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51028i06FDFC7C0A902079/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1663081411842.png" alt="JohannesLindner_1-1663081411842.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or do you mean something else? Then please clarify.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 15:06:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1212005#M26466</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-13T15:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the angle of a line respect to the North</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1212012#M26467</link>
      <description>&lt;P&gt;I deleted the other post as it was not quite correct, but if you extract your start and end points (&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/feature-vertices-to-points.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/feature-vertices-to-points.htm&lt;/A&gt;) and then use&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/defense/coordinate-table-to-line-of-bearing.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/tool-reference/defense/coordinate-table-to-line-of-bearing.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should be able to get what you need&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 15:32:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1212012#M26467</guid>
      <dc:creator>LukeCatania</dc:creator>
      <dc:date>2022-09-13T15:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the angle of a line respect to the North</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1212337#M26472</link>
      <description>&lt;P&gt;Thank you! I'm indeed calculating the geographic angle and your solution works well, but just in some cases it is odd. For example, for the lines in the image below the dashed line's angle results to be 177° and the one for the solid line is 354°, so they are both wrong... could it be due to the sense in which I drew the lines?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They should be : dashed line around 100° and solid line around 75°&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CeciliaMartinelli_1-1663149603287.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51138i5AF07A4F1128F83B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CeciliaMartinelli_1-1663149603287.png" alt="CeciliaMartinelli_1-1663149603287.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 10:01:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1212337#M26472</guid>
      <dc:creator>CeciliaMartinelli</dc:creator>
      <dc:date>2022-09-14T10:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the angle of a line respect to the North</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1212423#M26476</link>
      <description>&lt;P&gt;Indeed, the angle is dependent on the vertex order:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1663162177685.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51168i6B28F1ACF8E8425D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1663162177685.png" alt="JohannesLindner_1-1663162177685.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Removing that dependency is easy, but it wasn't quite as trivial as I thought. I thought I just had to replace the modulo 360 with modulo 180 (last line). That works for lines with a single segment, but polylines are still wrong:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_2-1663162893865.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51169i7E59DBDB8965A582/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_2-1663162893865.png" alt="JohannesLindner_2-1663162893865.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead, you have to convert to geographic angle inside the loop, not at the end:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get a list of line parts
var paths = Geometry($feature).paths
// for each part, loop through each segment and get its geographic angle
var angles = []
for(var p in paths) {
    var count_p = Count(paths[p])
    for(var q = 1; q &amp;lt; count_p; q ++) {
        var a_arith = Angle(paths[p][q], paths[p][q-1])
        var a_geo = (450 - a_arith) % 180 // 180 instead of 360, so that vertex order doesn't matter
        Push(angles, a_geo)
    }
}
// return the mean
return Mean(angles)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_3-1663163069321.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51170iE2B10F46ADDC9DDC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_3-1663163069321.png" alt="JohannesLindner_3-1663163069321.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 13:46:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-calculate-the-angle-of-a-line-respect-to/m-p/1212423#M26476</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-14T13:46:12Z</dc:date>
    </item>
  </channel>
</rss>

