Opened 4 years ago

Closed 3 years ago

#4880 closed defect (fixed)

ST_Azimuth with geography type returns incorrect value

Reported by: francoisb Owned by: robe
Priority: medium Milestone: PostGIS 3.1.4
Component: documentation Version: 3.1.x
Keywords: angle Cc:

Description

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

Change History (7)

comment:1 by francoisb, 4 years ago

This is a duplicate of #4840, actually.

The documentation change suggestion could still be applied, though.

comment:2 by pramsey, 4 years ago

Milestone: PostGIS 3.1.23.1.3

comment:3 by pramsey, 4 years ago

Milestone: 3.1.3PostGIS 3.1.3

Milestone renamed

comment:4 by robe, 3 years ago

Milestone: PostGIS 3.1.3PostGIS 3.1.4

In prep for 3.1.3 release

comment:5 by robe, 3 years ago

Component: postgisdocumentation
Owner: changed from pramsey to robe

comment:6 by Regina Obe <lr@…>, 3 years ago

In cb8b6b8/git:

Update ST_Azimuth to include more defs suggested by Francois Bonzon. References #4880 for PostGIS 3.1.4

comment:7 by Regina Obe <lr@…>, 3 years ago

Resolution: fixed
Status: newclosed

In 60314f5/git:

Update ST_Azimuth to include more defs suggested by Francois Bonzon. Closes #4880 for PostGIS 3.2.0

Note: See TracTickets for help on using tickets.