Opened 4 years ago

Closed 14 months ago

#4326 closed defect (fixed)

Circular strings distances are wrong

Reported by: komzpa Owned by: strk
Priority: medium Milestone: PostGIS 2.5.3
Component: postgis Version: 2.4.x
Keywords: Cc:

Description

03:23:10 [kom] > select ST_Distance('CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(1 6, 6 1, 9 7),(9 7, 3 13, 1 6)),COMPOUNDCURVE((3 6, 5 4, 7 4, 7 6),CIRCULARSTRING(7 6,5 8,3 6)))', 'CURVEPOLYGON(CIRCULARSTRING(-1 4, 0 5, 1 4, 0 3, -1 4))');
┌────────────────────┐
│    st_distance     │
├────────────────────┤
│ 0.0475665993629137 │
└────────────────────┘
(1 row)

Time: 35,112 ms

03:23:53 [kom] > select ST_Distance('CURVEPOLYGON(CIRCULARSTRING(-1 4, 0 5, 1 4, 0 3, -1 4))','CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(1 6, 6 1, 9 7),(9 7, 3 13, 1 6)),COMPOUNDCURVE((3 6, 5 4, 7 4, 7 6),CIRCULARSTRING(7 6,5 8,3 6)))');┌─────────────┐
│ st_distance │
├─────────────┤
│           0 │
└─────────────┘
(1 row)

Time: 1,292 ms

To find more: swap lw1 and lw2 in https://github.com/postgis/postgis/blob/svn-trunk/liblwgeom/cunit/cu_measures.c#L65

Change History (17)

comment:1 by robe, 4 years ago

Milestone: PostGIS 2.5.2PostGIS 2.5.3

comment:2 by pramsey, 3 years ago

In 17385:

Circular string distances have some failure modes, and test
suite should test everything bi-directionally.
References #4326

comment:3 by pramsey, 3 years ago

In 17386:

Circular string distances have some failure modes, and test
suite should test everything bi-directionally.
References #4326

comment:4 by pramsey, 3 years ago

In 17387:

Circular string distances have some failure modes, and test
suite should test everything bi-directionally.
References #4326

comment:5 by pramsey, 3 years ago

In 17388:

Circular string distances have some failure modes, and test
suite should test everything bi-directionally.
References #4326

comment:6 by pramsey, 3 years ago

Resolution: fixed
Status: assignedclosed

comment:7 by robe, 17 months ago

Resolution: fixed
Status: closedreopened

As noted by abobov on IRC this returns 0 instead of some non-zero answer

WITH DATA AS (SELECT 'SRID=3857;CURVEPOLYGON(CIRCULARSTRING(7874821 8715927,8907663 8715927,8844683 7750316,7937800 7750316,7874821 8715927))'::geometry AS a,
                     'SRID=3857;Point (5433865 8243495)'::geometry AS b)
 
SELECT st_distance(a, b), a && b AS bbox_intersect FROM DATA;

Returns:

0  false

I would expect it to return something in ballpark of applying ST_LineToCurve answer:

WITH DATA AS (SELECT ST_CurveToLine('SRID=3857;CURVEPOLYGON(CIRCULARSTRING(7874821 8715927,8907663 8715927,8844683 7750316,7937800 7750316,7874821 8715927))'::geometry) AS a,
                     'SRID=3857;Point (5433865 8243495)'::geometry AS b)
 
SELECT st_distance(a, b) FROM DATA;

which returns:

2271892.5770899933

comment:8 by pramsey, 14 months ago

The right answer pops out when it's just a point/line distance, so the problem must line in the containment test.

WITH data AS (
  SELECT 
    'CIRCULARSTRING(7874821 8715927,8907663 8715927,8844683 7750316,7937800 7750316,7874821 8715927)'::geometry AS a,
    'POINT(5433865 8243495)'::geometry AS b
) 
SELECT ST_Distance(a, b), a && b AS bbox_intersect FROM data;

comment:9 by Paul Ramsey <pramsey@…>, 14 months ago

Resolution: fixed
Status: reopenedclosed

In 98e1477/git:

Error in arc direction flagging, fixes #4326

comment:10 by Paul Ramsey <pramsey@…>, 14 months ago

In 74b40a7/git:

Error in arc direction flagging, fixes #4326

comment:11 by Paul Ramsey <pramsey@…>, 14 months ago

In e4c3f5e7/git:

Error in arc direction flagging, fixes #4326

comment:12 by Paul Ramsey <pramsey@…>, 14 months ago

In cfae0f16/git:

Error in arc direction flagging, fixes #4326

comment:13 by Paul Ramsey <pramsey@…>, 14 months ago

In 58b5c3b8/git:

Error in arc direction flagging, fixes #4326

comment:14 by pramsey, 14 months ago

Patched back to 2.4.

comment:15 by robe, 14 months ago

Resolution: fixed
Status: closedreopened

Added test broke many of the bots not running GEOS 3.9 see #4963

comment:16 by Regina Obe <lr@…>, 14 months ago

In 166721c/git:

Take out default arg in dist2dtest references #4963 , references #4326 for PostGIS 2.5

comment:17 by pramsey, 14 months ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.