IsPolygonCCW false negative result

24 views
Skip to first unread message

Anton Bakker

unread,
Jan 20, 2023, 5:58:39 AM1/20/23
to SpatiaLite Users
Hi, I am running into the following issue:

When determining polygon winding order for the set of geometries (all counterclockwise (CCW) orientation, total nr of geometries) the function `ST_IsPolygonCCW` returns `0` for these geometries, which is incorrect since al geometries have CCW orientation. The function `ST_IsPolygonCW` does return the correct result for all of these polygons. I am suspecting that this is not an issue with spatialite but with the underlying GEOS library, but wanted to check here first before opening an issue on the GEOS issue tracker. For details on how to reproduce the issue, see the following gist: https://gist.github.com/arbakker/47bbee69ce4194a41e32593731047f3e .

Kind regards,
Anton Bakker

a.fu...@lqt.it

unread,
Jan 20, 2023, 11:40:23 AM1/20/23
to spatiali...@googlegroups.com
Hi Anton,

first let's clear up a misunderstanding: both CW/CCW functions
are entirely based on internal code; GEOS is absolutely not
involved.

Coming to the results of your sample; they are always absolutely
correct, and let's see why.

accordingly to the documentation you can read from here:
https://www.gaia-gis.it/gaia-sins/spatialite-sql-5.0.1.html

====================================================================
IsPolygonCW
"returns TRUE (1) if all Polygons into the Geometry are oriented
accordingly to Clockwise Rule (all Exterior Ring must be clockwise
oriented, and all Interior Rings must be counter-clockwise oriented).
returns FALSE (0) if not; returns -1 on invalid Geometries."

IsPolygonCCW
"returns TRUE (1) if all Polygons into the Geometry are oriented
accordingly to Counter-Clockwise Rule (all Exterior Ring must be
counter-clockwise oriented, and all Interior Rings must be
clockwise oriented).
returns FALSE (0) if not: returns -1 on invalid Geometries."
====================================================================

all Polygons within your sampe have one or more Interior Rings
(holes), and for all them there is at least an Interior Ring
presenting the same orientation of the Exterior Ring.

short conclusion: all your Polygons are not respecting neither
the CW nor the CCW rules, and consequently the SQL Functions
correctly return a FALSE result.

final note: ST_IsPolygonCW() is not the reciprocal function
of ST_IsPolygonCCW()
Many Polygons with Interior Rings can easily violate both
CW and CCW rules (as in your sample).

bye Sandro

Anton Bakker

unread,
Jan 20, 2023, 12:13:57 PM1/20/23
to spatiali...@googlegroups.com
Hi Sandro,

Thanks for your response and explanation. 

Do you know how to check if all holes have the opposite orientation recursively? I wrongly assumed the IsValid call would account for that. 

Looking at the funtion reference list I know see for each function the required module is detailed and indeed the CCW functions are in the base.

Kind regards,
Anton

Op vr 20 jan. 2023 17:40 schreef <a.fu...@lqt.it>:
--
You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spatialite-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/spatialite-users/a51fbe31a68d2e86e16bffb308efb625%40lqt.it.

a.fu...@lqt.it

unread,
Jan 20, 2023, 1:59:15 PM1/20/23
to spatiali...@googlegroups.com
On Fri, 20 Jan 2023 18:13:42 +0100, Anton Bakker wrote:
> Hi Sandro,
>
> Thanks for your response and explanation. 
>
> Do you know how to check if all holes have the opposite orientation
> recursively? I wrongly assumed the IsValid call would account for
> that. 
>

Hi Anton,

note that the orientation CW/CCW of Polygon Rings (both Exteriors
and Interiors) has no relevance at all in modern Spatial Processing.

respecting a predefined orientation was a strict requisite imposed
by earlier GIS instrumentations, but we are speaking about fossil
relics longly disappeared from the scenes.

Compliance with a predefined orientation was a strict requirement
imposed from the very first GIS tools, but we are talking about
fossil wrecks that have disappeared from the scene for decades now.

Both the OGC SFS specifications and the subsequent ISO SQL-MM do not
impose anything in this regard, any orientation of Polygon Rings is
always assumed to be valid.

AFAIK only the very old and outdated ESRI Shapefile still imposes
to respect a given orientation for Polygon Rings, but this is a
detail that any Shapefile writing tool will automatically handle
(as does SpatiaLite itself).

However, if for any reason you feel the need to impose a given
CW/CCW rule to all your Polygons you can use
ST_ForcePolygonCW()
or
ST_ForcePolygonCCW()

bye Sandro



Reply all
Reply to author
Forward
0 new messages