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
Add support for dateline wrapping for circle to geometry conversion #194
Conversation
Signed-off-by: Stijn Caerts <stijncaerts@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice contribution!
double minX = -180 + page * 360; | ||
if (geomEnv.getMaxX() <= minX) | ||
break; | ||
Geometry rect = geom.getFactory().toGeometry(new Envelope(minX, minX + 360, -90, 90)); | ||
assert rect.isValid() : "rect"; | ||
Geometry pageGeom = rect.intersection(geom);//JTS is doing some hard work | ||
Geometry pageGeom = rect.intersection(geom).copy();//JTS is doing some hard work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shifting the intersection also alters the original geometry. Using the example from JtsSpatialContextTest
, here is an overview of the value of geom
in the cutUnwrappedGeomInto360
loop:
- Page 0
geom
: POLYGON ((181 -90, 179 -90, 179 90, 181 90, 181 -90))pageGeom
: POLYGON ((179 90, 180 90, 180 -90, 179 -90, 179 90))- Intersection isn't shifted because it is already in the -180 to 180 area.
- Page 1
geom
: POLYGON ((181 -90, 179 -90, 179 90, 181 90, 181 -90))pageGeom
: POLYGON ((180 -90, 180 90, 181 90, 181 -90, 180 -90))- Now the intersection is shifted -360 degrees
- Page 2
geom
: POLYGON ((181 -90, 179 -90, 179 90, 181 90, -179 -90))- No intersection is calculated because the geometry doesn't span across this page. But notice that the original geometry has changed by shifting the intersection in the previous iteration.
But when we start on a negative page, we already shift in the first iteration and then the geometry is messed up for the following iterations. This hasn't been noticed in the tests because all tested geometries only have 2 pages (0 and 1). If it is possible to have more than 2 pages, you would see the same problem there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shifting the intersection also alters the original geometry.
Woah; I thought the intersection produced an entirely new geometry!
I'm glad you are looking into this. If it's not asking too much, perhaps a new test might perturb these problems.
@@ -573,17 +573,16 @@ private static Geometry cutUnwrappedGeomInto360(Geometry geom) { | |||
return geom; | |||
assert geom.isValid() : "geom"; | |||
|
|||
//TODO opt: support geom's that start at negative pages -- | |||
// ... will avoid need to previously shift in unwrapDateline(geom). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think you can address this second line of the comment you deleted? if you look in unwrapDateline(LineString)
, there will be a final shifting going on that I think the improvement you added here obsoletes. Granted I wrote that 8 years ago so I'm a little unclear now looking back at it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will take a look at it!
HI Stijn. I'm looking to do a Spatial4j release soon and I'm not sure what to do related to this issue right now. I could merge as-is -- it's an improvement. Or maybe you feel it's insufficient. If Spatial4j is released without this... it would honestly be a long time before another release occurred based on the track record here. |
Hi David, I think it is better then to include the changes as-is in the release. I was still looking into removing the shift in |
Codecov Report
@@ Coverage Diff @@
## master #194 +/- ##
============================================
+ Coverage 75.85% 75.98% +0.12%
- Complexity 1108 1112 +4
============================================
Files 57 57
Lines 3822 3826 +4
Branches 774 775 +1
============================================
+ Hits 2899 2907 +8
+ Misses 644 642 -2
+ Partials 279 277 -2
Continue to review full report at Codecov.
|
I think I might have a clue why the Fiji test fails when the final shift is removed in So are these values incorrect in the included WKT or are they there intentionally? |
Stijn, can you please submit an Eclipse Contributor License Agreement: https://projects.eclipse.org/user/sign/cla |
Signed-off-by: Stijn Caerts <stijncaerts@gmail.com>
454c925
to
ca3b490
Compare
I submitted the Eclipse Contributor License Agreement and added a sign-off to one of the commits. |
Added support for dateline wrapping when converting a circle to a geometry. I implemented it like this;
JtsGeometry::cutUnwrappedGeomInto360()
JtsGeometry
if the circle crosses the dateline