Opened 2 years ago

Closed 21 months ago

#5089 closed defect (fixed)

ST_Reverse does not handle CURVEPOLYGON/COMPOUNDCURVE correctly

Reported by: bhoefling Owned by: strk
Priority: medium Milestone: PostGIS 3.3.0
Component: liblwgeom Version: 3.2.x
Keywords: Cc: bhoefling

Description

ST_Reverse works for CIRCULARSTRING, and for simple CURVEPOLYGON.

But if the CURVEPOLYGON contains a COMPOUNDCURVE with more than one component, the reverse order is wrong.

Testcase is from here:

https://github.com/postgis/postgis/blob/f6def67654c25d812446239036cee44812613748/regress/core/reverse.sql#L47

Actual Result:

SELECT 'cplg2', ST_AsText(ST_Reverse('CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (0 0,1 1,1 0),(1 0,0 1),(0 1,0 0)))'::geometry));

?column? | st_astext


cplg2 | CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(1 0,1 1,0 0),(0 1,1 0),(0 0,0 1)))

(1 row)

Note that each sub-component is reversed. But it is necessary to additionally reverse the order of the components as such. Otherwise, the end/start nodes don't match any more.

EXPECTED:

CURVEPOLYGON(COMPOUNDCURVE((0 0,0 1), (0 1,1 0), CIRCULARSTRING(1 0,1 1,0 0)))

Implementation details: lwgeom.c, lwgeom_reverse_in_place(LWGEOM *geom)

https://github.com/postgis/postgis/blob/2fb15205263248249b1f1dd09abc117e8f67807c/liblwgeom/lwgeom.c#L135

This CASE needs to be differentiated more.

Tested on Docker postgis/postgis:13-master

SELECT postgis_full_version();

— POSTGIS="3.3.0dev 3.2.0-398-g4fa57df0b" [EXTENSION] PGSQL="130" GEOS="3.11.0dev-CAPI-1.16.0" PROJ="8.2.0" LIBXML="2.9.10" LIBJSON="0.15" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)" (core procs from "3.1.4 ded6c34" need upgrade)

SELECT version();

version


PostgreSQL 13.5 (Debian 13.5-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit

Björn

Change History (4)

comment:1 by bhoefling, 2 years ago

Cc: bhoefling added

comment:2 by bhoefling, 2 years ago

For reference, here is an older bug that fixed the CURVESTRING case:

https://trac.osgeo.org/postgis/ticket/2411

https://trac.osgeo.org/postgis/changeset/15566

comment:3 by pramsey, 21 months ago

Fixed in master at e87cf16e6/git

comment:4 by pramsey, 21 months ago

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