[postgis-devel] ST_Normalize issues (was ST_Reverse issues)

Paul Ramsey pramsey at cleverelephant.ca
Thu Jun 24 08:17:04 PDT 2021


The linestrings that are output from an OverlayNG Union operation are not necessarily oriented the same as those output by an old style Overlay, and in order to harmonize regression results when bringing in GEOS 3.9 (NG) with results run against older GEOS, normalize was made more stringent.

P

> On Jun 24, 2021, at 8:06 AM, Sandro Santilli <strk at kbt.io> wrote:
> 
> So it looks like ST_Normalize sometimes changes winding order
> of closed linestrings to be CW and sometimes changes them to be CCW
> 
> Here's an example:
> 
>  WITH inp AS (
>    SELECT 't1' lbl, 'LINESTRING(0 0,10 0,5 5,0 0)'::geometry g
>    UNION ALL
>    SELECT 't3', 'LINESTRING(0 0,-10 0,-5 -5,0 0)'::geometry
>  ),
>  back_and_forw AS (
>    SELECT lbl, g, st_reverse(g) rg from inp
>  )
>  SELECT
>    -- We expect both fields being true
>    lbl,
>      ST_AsText(g) forw,
>      ST_AsText(rg) back,
>      ST_AsText(ST_Normalize(g)) norm_forw,
>      ST_AsText(ST_Normalize(rg)) norm_back,
>      ST_IsPolygonCW(ST_MakePolygon(g)) forw_cw,
>      ST_IsPolygonCW(ST_MakePolygon(rg)) back_cw,
>      ST_IsPolygonCW(ST_MakePolygon(ST_Normalize(g))) norm_forw_cw,
>      ST_IsPolygonCW(ST_MakePolygon(ST_Normalize(rg))) norm_back_cw
>  FROM back_and_forw;
> 
> The result:
> 
> 
>    -[ RECORD 1 ]+--------------------------------
>    lbl          | t1
>    forw         | LINESTRING(0 0,10 0,5 5,0 0)
>    back         | LINESTRING(0 0,5 5,10 0,0 0)
>    norm_forw    | LINESTRING(0 0,5 5,10 0,0 0) 
>    norm_back    | LINESTRING(0 0,5 5,10 0,0 0)
>    forw_cw      | f
>    back_cw      | t
>    norm_forw_cw | t
>    norm_back_cw | t
>    -[ RECORD 2 ]+--------------------------------
>    lbl          | t3
>    forw         | LINESTRING(0 0,-10 0,-5 -5,0 0)
>    back         | LINESTRING(0 0,-5 -5,-10 0,0 0)
>    norm_forw    | LINESTRING(0 0,-10 0,-5 -5,0 0)
>    norm_back    | LINESTRING(0 0,-10 0,-5 -5,0 0)
>    forw_cw      | f
>    back_cw      | t
>    norm_forw_cw | f
>    norm_back_cw | f
> 
> 
> The above was obtained with:
> 
>  POSTGIS="3.1.2dev 3.1.1-38-gb02ee9513"
>  PGSQL="120"
>  GEOS="3.8.2dev-CAPI-1.13.4"
>  PROJ="7.1.0"
>  LIBXML="2.9.10"
>  LIBJSON="0.15"
>  LIBPROTOBUF="1.3.3"
> 
> Does it ring any bell to anyone of you ? Or I guess I'll file a
> ticket.
> 
> --strk;
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-devel



More information about the postgis-devel mailing list