locationtech/spatial4j

JtsGeometry:unwrapDateline does not work for polygon that wraps around the globe

JacobBrandt opened this issue · 2 comments

So on this line we're changing the sequence by shiftXPage * 360.
https://github.com/locationtech/spatial4j/blob/master/src/main/java/org/locationtech/spatial4j/shape/jts/JtsGeometry.java#L502

On this line we make sure that the end and beginning coordinates are the same, however it fails to check if we have an outstanding X shift. It assumes you cross back over the dateline. That's not true for polygons that wrap around the globe. You'll only cross the dateline once. https://github.com/locationtech/spatial4j/blob/master/src/main/java/org/locationtech/spatial4j/shape/jts/JtsGeometry.java#L506
So these two asserts should basically check if shiftXPage != 0 than the last X coordinate is going to be shiftXPage * 360 from the first X coordinate.

Hello @JacobBrandt . It's a known issue that JtsGeometry doesn't support polygons that cover a pole -- issue #5 which is what I think you mean? I think a solution to that issue is much more than a simple matter of adjusting the asserts or condition that you point too -- the polygon will need to be extended to the pole (and figure out which pole). But in the mean time maybe we could throw a more specific error that this isn't supported?

@dsmiley Ah sorry, yes that's the same issue. Could we discuss what the changes would entail? I don't mind contributing as I need this to work.