The following bug has been logged on the website:
Bug reference: 17037
Logged by: Jan Heckman
Email address: jan.heckman@gmail.com
PostgreSQL version: 11.11
Operating system: windows 10 pro 21H1
Description:
The following queries illustrate that ST_Azimuth can fail to follow
https://postgis.net/docs/ST_Azimuth.html with dy < 0 and dx < 0.
The first three queries produce correct results, the last one does not:
select degrees(st_azimuth('POINT(0 1)'::geometry,'POINT(0 0)'::geometry));
degrees
---------
180
(1 row)
select degrees(st_azimuth('POINT(0 1)'::geography,'POINT(0
0)'::geography));
degrees
---------
180
(1 row)
select degrees(st_azimuth('POINT(0 1)'::geometry,'POINT(-0.01
0)'::geometry));
degrees
------------------
180.572938697683
(1 row)
select degrees(st_azimuth('POINT(0 1)'::geography,'POINT(-0.01
0)'::geography));
degrees
------------------
359.423171739084
(1 row)
This behavior occurs also with less 'nice' inputs, e.g.
select degrees(st_azimuth(ST_POINT(4.76389,
52.308601)::geography,'POINT(4.43722 51.956902)'::geography));
degrees
-----------------
330.11876325276
This is NOT the course to fly from airport AMS to airport RTM.
Doing the query with geometry instead of geography produces a better result,
but should be inaccurate for greater distances:
select degrees(st_azimuth(ST_POINT(4.76389,
52.308601)::geometry,'POINT(4.43722 51.956902)'::geometry));
degrees
------------------
222.886982058682