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

ST_MakeValid changes the order of points in a polygon #1754

Open
atiannicelli opened this issue Jan 13, 2025 · 3 comments
Open

ST_MakeValid changes the order of points in a polygon #1754

atiannicelli opened this issue Jan 13, 2025 · 3 comments

Comments

@atiannicelli
Copy link

I think that all polygons in OSM and other datasets are supposed to be ordered in such a way that the points in the polygon are listed in counter clockwise direction.

Here is an example. I gave it this polygon:
POLYGON ((10.947076 45.9679118, 10.9471748 45.967871, 10.9472574 45.9679588, 10.9471571 45.9680032, 10.947076 45.9679118))

And asked it to apply ST_MakeValid on it and it gave me this:
POLYGON ((10.947076 45.9679118, 10.9471571 45.9680032, 10.9472574 45.9679588, 10.9471748 45.967871, 10.947076 45.9679118))

Here is a picture of that polygon with the first (and last) node highlited.
Image

Here is a picture of that same polygon with the first and second point of the original polygon highlighted showing that the order indicates that it is counter-clockwise - This is correct!
Image

Here is a picture of that same polygon with the first and second point of the polygon that was created with ST_MakeValid highlighted showing that the order indicates that it is clockwise - This is Wrong!
Image

@james-willis
Copy link
Contributor

james-willis commented Jan 13, 2025

You are right that exterior rings should be CCW. IME having them CW is typically not an issue.

Which version of sedona/jts are you using? Does this repro in JTS 1.20?

Can you repro the issue in JTS and file a bug there? If you do, please link back to here.

MakeValid just wraps the JTS GeometryFixer class: https://github.com/apache/sedona/blob/master/common/src/main/java/org/apache/sedona/common/Functions.java#L1126

As Jia mentioned on Discord, you can probably use ST_ForcePolygonCCW to work aroudn this issue for now.

@atiannicelli
Copy link
Author

I'm not sure the jts version. I'm running in AWS glue 4.0.
I am specifying the jts.overlay=ng
Sedonda version was 1.6.1 when I hit the issue.

I've since upgraded to 1.7.0 and I'm using the new ST_RemoveRepeatedPoints to do what I was trying to accomplish with the ST_MakeValid function.

@james-willis
Copy link
Contributor

james-willis commented Jan 15, 2025

I'm not sure the jts version.

sedona 1.6.1 is JTS 1.19: https://github.com/apache/sedona/blob/sedona-1.6.1/pom.xml#L74

I am specifying the jts.overlay=ng

This shouldn't matter, that should only affect ie intersection, union, etc calls.

It would be good to test this behavior in JTS 1.20 and file a bug in that repo. I searched past issues there and didn't find anything.

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

No branches or pull requests

2 participants