Skip to main content

Hi

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

Thanks

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


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

 

 


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