ST_Azimuth

Syntax

DOUBLE ST_Azimuth(GEOPOINT point1, GEOPOINT point2)

description

Enter two point, and returns the azimuth of the line segment formed by points 1 and 2. The azimuth is the angle in radians measured between the line from point 1 facing true North to the line segment from point 1 to point 2.

The positive angle is measured clockwise on the surface of a sphere. For example, the azimuth for a line segment:

  • Pointing North is 0
  • Pointing East is PI/2
  • Pointing South is PI
  • Pointing West is 3PI/2

ST_Azimuth has the following edge cases:

  • If the two input points are the same, returns NULL.
  • If the two input points are exactly antipodal, returns NULL.
  • If either of the input geographies are not single points or are the empty geography, throws an error.

example

  1. mysql> SELECT st_azimuth(ST_Point(1, 0),ST_Point(0, 0));
  2. +----------------------------------------------------+
  3. | st_azimuth(st_point(1.0, 0.0), st_point(0.0, 0.0)) |
  4. +----------------------------------------------------+
  5. | 4.71238898038469 |
  6. +----------------------------------------------------+
  7. 1 row in set (0.03 sec)
  8. mysql> SELECT st_azimuth(ST_Point(0, 0),ST_Point(1, 0));
  9. +----------------------------------------------------+
  10. | st_azimuth(st_point(0.0, 0.0), st_point(1.0, 0.0)) |
  11. +----------------------------------------------------+
  12. | 1.5707963267948966 |
  13. +----------------------------------------------------+
  14. 1 row in set (0.01 sec)
  15. mysql> SELECT st_azimuth(ST_Point(0, 0),ST_Point(0, 1));
  16. +----------------------------------------------------+
  17. | st_azimuth(st_point(0.0, 0.0), st_point(0.0, 1.0)) |
  18. +----------------------------------------------------+
  19. | 0 |
  20. +----------------------------------------------------+
  21. 1 row in set (0.01 sec)
  22. mysql> SELECT st_azimuth(ST_Point(0, 1),ST_Point(0, 1));
  23. +----------------------------------------------------+
  24. | st_azimuth(st_point(0.0, 1.0), st_point(0.0, 1.0)) |
  25. +----------------------------------------------------+
  26. | NULL |
  27. +----------------------------------------------------+
  28. 1 row in set (0.02 sec)
  29. mysql> SELECT st_azimuth(ST_Point(-30, 0),ST_Point(150, 0));
  30. +--------------------------------------------------------+
  31. | st_azimuth(st_point(-30.0, 0.0), st_point(150.0, 0.0)) |
  32. +--------------------------------------------------------+
  33. | NULL |
  34. +--------------------------------------------------------+
  35. 1 row in set (0.02 sec)

keywords

ST_AZIMUTH,ST,AZIMUTH