Select to view content in your preferred language

Calculate angle of polyline using field calculator?

1364
4
Jump to solution
09-14-2022 03:16 PM
avonmoos
Regular Contributor

Anyone have a code snippet I can use to accomplish this?

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

I'm currently answering a similar question here:

Re: How to calculate the angle of a line respect t... - Esri Community


Have a great day!
Johannes

View solution in original post

4 Replies
DanLee
by Esri Regular Contributor
Esri Regular Contributor

Calculate Geometry Attributes can calculate Line Bearing, if that's what you need.

https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-geometry-attribute...

 

DanPatterson
MVP Esteemed Contributor
JohannesLindner
MVP Frequent Contributor

I'm currently answering a similar question here:

Re: How to calculate the angle of a line respect t... - Esri Community


Have a great day!
Johannes
avonmoos
Regular Contributor

This is what I ended up going with. Thanks!

// get a list of line parts
var paths = Geometry($feature).paths
// for each part, loop through each segment and get its angle (arithmetic angle -> East=0°, North=90°)
var angles = []
for(var p in paths) {
    var count_p = Count(paths[p])
    for(var q = 1; q < 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 - 180
return north_arith_angle + IIF(north_arith_angle < 0, 180, 0)
0 Kudos