Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: function to force orientation of polygon rings #779

Closed
jorisvandenbossche opened this issue Dec 28, 2022 · 1 comment · Fixed by #818
Closed

Feature: function to force orientation of polygon rings #779

jorisvandenbossche opened this issue Dec 28, 2022 · 1 comment · Fixed by #818
Assignees

Comments

@jorisvandenbossche
Copy link
Contributor

Being able to force the orientation of rings to be (counter-)clock-wise would be useful for certain use cases (eg some file formats or applications require a specific orientation).

For reference, PostGIS has this functionality as ST_ForcePolygonCCW and ST_ForcePolygonCW.
Shapely has this functionality as shapely.ops.orient(..) based on a custom python implementation (impl). But, this is currently a pure python function and not available as fast vectorized function (wrapping GEOS at the C level), and so shapely could benefit from a GEOS C API function for this (shapely/shapely#1366).

GEOS already exposes a method to check for the orientation of a coordinate sequence in the C API function: GEOSCoordSeq_isCCW.

@jorisvandenbossche
Copy link
Contributor Author

Some thoughts on a possible API: although GEOSCoordSeq_isCCW as prior art works on an individual coordinate sequence, for usability (eg in shapely), it would be easier to have a function that works on an actual GEOSGeometry and transforms any ring contained in the geometry (like the PostGIS functions).
Of course, something like this needs more logic (for example, the expectation is then to transform inner rings of polygons using the opposite orientation), and it is possible to keep this logic in consumers of the API like shapely.

On the other hand, if this logic lives in bindings like shapely, then you can already do that right now with GEOSCoordSeq_isCCW and GEOSReverse on the individual LinearRings.

Quoting @dr-jts from the shapely issue:

Perhaps a function GEOSOrientPolygon(Geometry, boolean isCW), to allow orienting either shell-CW (the GEOS default) or shell-CCW.

@dbaston dbaston self-assigned this Feb 2, 2023
dbaston added a commit to dbaston/libgeos that referenced this issue Feb 2, 2023
dbaston added a commit to dbaston/libgeos that referenced this issue Mar 9, 2023
dbaston added a commit that referenced this issue May 4, 2023
* Add GEOSOrientPolygons

Fixes #779

Co-authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants