[postgis-devel] ST_Normalize issues (was ST_Reverse issues)
Sandro Santilli
strk at kbt.io
Thu Jun 24 08:06:18 PDT 2021
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;
More information about the postgis-devel
mailing list