Select to view content in your preferred language

Obtain bearing of a geodesic line using arcpy

439
2
10-20-2023 07:09 AM
JuanKlahr
New Contributor

Hi,

I'm trying to get the bearing of a geodesic line in a script, but cannot find a tool that can be used for that in arcpy. The Distance and Direction tool lets me get the bearing, however cannot be used in arcpy. 

Any help would be appreciated!

0 Kudos
2 Replies
AlfredBaldenweck
MVP Regular Contributor

Try calculate geometry?

Add Geometry Attributes (Data Management)—ArcGIS Pro | Documentation

Only issue is that it modifies your table.

0 Kudos
DavidSolari
Occasional Contributor III

Untested, but this should get you in the ballpark:

 

# Get this polyline object somehow, cursors with the "SHAPE@" token work well
line = get_line()

sr = line.spatialReference
start = arcpy.PointGeometry(line.firstPoint, spatial_reference=sr)
end = arcpy.PointGeometry(line.lastPoint, spatial_reference=sr)

angle, distance = start.angleAndDistanceTo(end, "GEODESIC")

Peep the "angleAndDistanceTo" part of the PointGeometry docs for more info.

 

0 Kudos