Skip to main content
Question

Azimuth to compass direction/bearing?

  • August 1, 2016
  • 5 replies
  • 132 views

Forum|alt.badge.img

Hi

Whats the easiest way to get the Azimuth to a compass bearing?

Thanks

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

bruceharold
Supporter
Forum|alt.badge.img+19
  • Supporter
  • 349 replies
  • August 1, 2016
    #Function to return the north azimuth bearing of a line segment in degrees
    def NorthAzimuth(x1,y1,x2,y2):
        degBearing = math.degrees(math.atan2((x2 - x1),(y2 - y1)))
        if (degBearing < 0):
            degBearing += 360.0
        return degBearing 

That is Python to return compass bearing.  Math functions return arithmetic azimuth already.


bruceharold
Supporter
Forum|alt.badge.img+19
  • Supporter
  • 349 replies
  • August 1, 2016
    #Function to return the north azimuth bearing of a line segment in degrees
    def NorthAzimuth(x1,y1,x2,y2):
        degBearing = math.degrees(math.atan2((x2 - x1),(y2 - y1)))
        if (degBearing < 0):
            degBearing += 360.0
        return degBearing 

That is Python to return compass bearing.  Math functions return arithmetic azimuth already.

...and I know it uses atan2 the 'wrong way round' but that is how the direction reversal works...


  • 5 replies
  • April 11, 2018

@bruceharold Hi there, i to require the azimuth angle to be converted into a bearing where 0 degrees is North. How do i add the above python script into my workbench...i'm not too familiar with python it's self but am good at following instructions :)

Any help would be much appreciated.

Cheers

Trent


bruceharold
Supporter
Forum|alt.badge.img+19
  • Supporter
  • 349 replies
  • April 11, 2018

@bruceharold Hi there, i to require the azimuth angle to be converted into a bearing where 0 degrees is North. How do i add the above python script into my workbench...i'm not too familiar with python it's self but am good at following instructions :)

Any help would be much appreciated.

Cheers

Trent

Hi, get the start and end coordinates of a line into x1,y1,x2,y2 attributes, pick these up in a PythonCaller (be sure to import math) and send them to the function. The helpful staff at Safe will guide you.

 

 


  • 5 replies
  • April 11, 2018
Hi, get the start and end coordinates of a line into x1,y1,x2,y2 attributes, pick these up in a PythonCaller (be sure to import math) and send them to the function. The helpful staff at Safe will guide you.

 

 

@bruceharold Thanks for the quick reply, i can pull the start and end vertexes of the line using the CoordinateExtractor. I'm not sure what you mean around import math and send to the function as i'm not familiar with the PythonCaller and how it should look or be set up, and how do i push the bearing into a new field?