[postgis-users] ST_CurveToLine and ST_LineToCurve problems

Marcin Mionskowski mionskowskimarcin at gmail.com
Wed Nov 10 07:24:29 PST 2021


Dear List,
I ran across two issues with CurvePolygons today:

1. "The last vertex problem" - result of ST_CurveToLine conversion is
missing the "last" vertex:

with
p as (select ST_SetSRID(ST_MakePoint(500000,600000),2180) geom) --just a
point
, b as (select st_buffer(geom,10,2) geom from p) --simple buffer
, c as (select ST_LineToCurve(geom) geom from b) --conversion to
CurvePolygon with expected result: SRID=2180;CURVEPOLYGON (CIRCULARSTRING
(500010.0 600000.0, 499990.0 600000.0, 500010.0 600000.0))
select ST_CurveToLine(c.geom,2)
from c

The result looks like this:

[image: curve2line.png]
WKT: POLYGON ((500010 600000, 500007.07106781186 600007.0710678119, 500000
600010, 499992.92893218814 600007.0710678119, 499990 600000,
499992.92893218814 599992.9289321881, 500000 599990, 500010 600000))
Clearly the last "high precission" coordinate pair is missing.
The buffer distance and number of segments in quadrant in line2curve
conversion does not matter, at least in my testing.
The tolerance (number of segments) in curve2line conversion on the other
hand matters - in range from 2 to 1000 for 35 tolerances the result is
"correct":{61,122,197,244,343,345,355,359,375,379,393,394,473,487,488,686,690,693,699,701,710,711,718,733,750,758,786,788,795,801,946,965,974,976,999}
They can be selected with following query:
with
p as (select ST_SetSRID(ST_MakePoint(500000,600000),2180) geom) --just a
point
, b as (select st_buffer(geom,10,2) geom from p) --simple buffer
, c as (select ST_LineToCurve(geom) geom from b) --conversion to
CurvePolygon with expected result: SRID=2180;CURVEPOLYGON (CIRCULARSTRING
(500010.0 600000.0, 499990.0 600000.0, 500010.0 600000.0))
select array_agg(gs)--,ST_NPoints(ST_CurveToLine(c.geom,gs)) np
from c
,generate_series(2,1000) gs
where gs*4-ST_NPoints(ST_CurveToLine(c.geom,gs))=-1



2. "Equality problem" - CurvePolygons generated from the same distance
buffers of a single point (differing only in number of segments in
quadrants) are not the same:

with
p as (select ST_SetSRID(ST_MakePoint(500000,600000),2180) geom) --just a
point
, b as (select gs,st_buffer(geom,10,gs) geom from p,generate_series(2,1000)
gs) --some buffers around the point (only the number of segments per
quadrant differs)
, c as (select gs,ST_LineToCurve(geom) geom from b) --conversion to
curvepolygons
select array_agg(gs order by gs),geom --grouping by curvepolygon geometry
to check equality
from c
group by geom
order by 1;

The larger the buffer, the more homogeneous the results - with 1 m buffer
I'm getting 948 distinct (in WKT terms) CurvePolygons, with 100 m buffer
there are only 2 different results.



So... Are what I have described bugs or is it supposed to work this way?
My PG versions:
PostgreSQL 13.4 (Ubuntu 13.4-4.pgdg20.04+1) on x86_64-pc-linux-gnu,
compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit
POSTGIS="3.1.4 ded6c34" [EXTENSION] PGSQL="130" GEOS="3.8.0-CAPI-1.13.1 "
PROJ="6.3.1" LIBXML="2.9.10" LIBJSON="0.13.1" LIBPROTOBUF="1.3.3"
WAGYU="0.5.0 (Internal)" (core procs from "3.1.1 aaf4c79" need upgrade)

Regards,
Marcin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20211110/097aac96/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: curve2line.png
Type: image/png
Size: 7546 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20211110/097aac96/attachment.png>


More information about the postgis-users mailing list