Skip to content

Commit

Permalink
improvement: check geometry crosses dateline
Browse files Browse the repository at this point in the history
Signed-off-by: qGYdXbY2 <[email protected]>
  • Loading branch information
qGYdXbY2 committed Aug 15, 2024
1 parent 617a984 commit 0fc2579
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,25 @@ static Geometry toPolygonGeometry(Collection<Polygon> polygons) {
public static boolean geometryCrossesDateline(com.here.xyz.models.geojson.implementation.Geometry geometry, int radius)
throws NullPointerException, NoSuchAuthorityCodeException, FactoryException, MismatchedDimensionException, TransformException
{
MathTransform convertToMeter = mathTransform("EPSG:4326", "EPSG:31300");
MathTransform convertFromMeter = mathTransform("EPSG:31300", "EPSG:4326");

Geometry degGeo = geometry.getJTSGeometry(),
mtrGeo = JTS.transform( degGeo, convertToMeter );
Geometry degGeo = geometry.getJTSGeometry();

if (radius > 0) {
MathTransform convertToMeter = mathTransform("EPSG:4326", "EPSG:31300");
MathTransform convertFromMeter = mathTransform("EPSG:31300", "EPSG:4326");

Geometry mtrGeo = JTS.transform( degGeo, convertToMeter );
mtrGeo = mtrGeo.buffer(radius);
degGeo = JTS.transform(mtrGeo, convertFromMeter);
}

degGeo = JTS.transform(mtrGeo, convertFromMeter);
Envelope envelope = degGeo.getEnvelopeInternal();

boolean r1 = envelope.intersects( 179.999995, envelope.centre().y),
r2 = envelope.intersects(-179.999995, envelope.centre().y),
r3 = ( envelope.getMinX() * envelope.getMaxX() ) < 0;

return (r1 || r2) && r3;
}
}

}

0 comments on commit 0fc2579

Please sign in to comment.