Categories:

Geospatial Functions

ST_AZIMUTH

Given two Points, returns the azimuth (in radians) of the line segment formed by the two points.

The azimuth is the angle from north to the line segment. The angle is positive in the clockwise direction and is:

  • 0 for a line segment pointing north.

  • π/2 for a line segment pointing east.

  • π for a line segment pointing south.

  • 3π/2 for a line segment pointing west.

If the two Points are the same location, the function returns NULL.

On a spherical Earth, the formula described here is used to determine the azimuth.

Caution

Systems using an elliptical Earth model use a more complex algorithm for Azimuth, which occasionally yields significantly different results.

Syntax

ST_AZIMUTH( <geography_expression_1> , <geography_expression_2> )

Arguments

geography_expression_1

A GEOGRAPHY object that is a Point.

geography_expression_2

A GEOGRAPHY object that is a Point.

Returns

Returns a value of type REAL that is the azimuth in radians.

Usage Notes

  • Returns NULL if one or both input points are NULL.

Examples

The following example returns the azimuth in radians for two points that form a line segment pointing south:

SELECT ST_AZIMUTH(
    TO_GEOGRAPHY('POINT(0 1)'),
    TO_GEOGRAPHY('POINT(0 0)')
);
+---------------------------------+
|                     ST_AZIMUTH( |
|     TO_GEOGRAPHY('POINT(0 1)'), |
|      TO_GEOGRAPHY('POINT(0 0)') |
|                               ) |
|---------------------------------|
|                     3.141592654 |
+---------------------------------+

The following example returns the azimuth in degrees for two points that form a line segment pointing northeast:

SELECT DEGREES(ST_AZIMUTH(
    TO_GEOGRAPHY('POINT(0 1)'),
    TO_GEOGRAPHY('POINT(1 2)')
));
+---------------------------------+
|             DEGREES(ST_AZIMUTH( |
|     TO_GEOGRAPHY('POINT(0 1)'), |
|      TO_GEOGRAPHY('POINT(1 2)') |
|                              )) |
|---------------------------------|
|                    44.978182941 |
+---------------------------------+