Skip to main content
Question

Azimuth to compass direction/bearing?


Forum|alt.badge.img

Hi

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

Thanks

5 replies

bruceharold
Contributor
Forum|alt.badge.img+17
  • Contributor
  • 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
Contributor
Forum|alt.badge.img+17
  • Contributor
  • August 1, 2016
bruceharold wrote:
    #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...


@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
Contributor
Forum|alt.badge.img+17
  • Contributor
  • April 11, 2018
trentanderin wrote:

@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.

 

 


bruceharold wrote:
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?

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings