[postgis-tickets] [PostGIS] #4880: ST_Azimuth with geography type returns incorrect value
PostGIS
trac at osgeo.org
Thu Mar 11 07:00:44 PST 2021
#4880: ST_Azimuth with geography type returns incorrect value
-----------------------+---------------------------
Reporter: francoisb | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS 3.1.2
Component: postgis | Version: 3.1.x
Keywords: angle |
-----------------------+---------------------------
It seems #4718 is a regression.
Perfect west 270° (3π/2 rad) - the only value in the regression test from
tickets.sql which had a negative result in the previous code - is by
chance correct, but all other expected results in the range 180°-360°
(π-2π rad) are incorrect.
Second, a perfect north (value exactly 0) is now incorrectly returned as
180° (π rad), instead of 0.
The fix is simple. Expected formula in lwgeodetic.c line 2180 is:
{{{
return az < 0 ? az + 2.0 * M_PI : az;
}}}
instead of:
{{{
return az > 0 ? az : M_PI - az;
}}}
Regression test from tickets.sql should add additional values, say at 45°
(Northeast, π/4) and at 315° (Northwest, 7π/4).
Documentation for ST_Azimuth could be extended to read:
North = 0; Northeast = π/4; East = π/2; Southeast = 3π/4; South = π;
Southwest 5π/4; West = 3π/2; Northwest = 7π/4
instead of:
North = 0; East = π/2; South = π; West = 3π/2
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4880>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list