HOW TO
In the attribute table of the ArcGIS Enterprise portal and ArcGIS Online, the average geographic angle of polylines can be calculated using ArcGIS Arcade. Finding the average angle of a line determines the overall trend of a line feature, and can be useful in fields such as construction, engineering and cartography. This article provides the workflow.
var paths = Geometry($feature).paths; var totalAngle = 0; var segmentCount = 0;
for (var p in paths) { var path = paths[p]; var count_p = Count(path);
for (var q = 1; q < count_p; q++) { var angle_p = Angle(path[q], path[q - 1]);
var geographicAngle = (450 - angle_p) % 180;
if (geographicAngle < 0) { geographicAngle += 180; }
totalAngle += geographicAngle; segmentCount++; } }
var averageAngle = 0; if (segmentCount > 0) { averageAngle = totalAngle / segmentCount; } return averageAngle;
The code block below shows the full working script.
var paths = Geometry($feature).paths; var totalAngle = 0; var segmentCount = 0; for (var p in paths) { var path = paths[p]; var count_p = Count(path); for (var q = 1; q < count_p; q++) { var angle_p = Angle(path[q], path[q - 1]); var geographicAngle = (450 - angle_p) % 180; if (geographicAngle < 0) { geographicAngle += 180; } totalAngle += geographicAngle; segmentCount++; } } var averageAngle = 0; if (segmentCount > 0) { averageAngle = totalAngle / segmentCount; } return averageAngle;
The image below shows the average geographic angle of polylines calculated in the attribute table.
Get help from ArcGIS experts
Download the Esri Support App