java.lang.Object
org.elasticsearch.geometry.utils.SpatialEnvelopeVisitor
- All Implemented Interfaces:
GeometryVisitor<Boolean,
RuntimeException>
public class SpatialEnvelopeVisitor
extends Object
implements GeometryVisitor<Boolean,RuntimeException>
This visitor is designed to determine the spatial envelope (or BBOX or MBR) of a potentially complex geometry.
It has two modes:
- Cartesian mode: The envelope is determined by the minimum and maximum x/y coordinates. Incoming BBOX geometries with minX > maxX are treated as invalid. Resulting BBOX geometries will always have minX <= maxX.
- Geographic mode: The envelope is determined by the minimum and maximum x/y coordinates, considering the possibility of wrapping the longitude around the dateline. A bounding box can be determined either by wrapping the longitude around the dateline or not, and the smaller bounding box is chosen. It is possible to disable the wrapping of the longitude.
Optional<Rectangle> bbox = SpatialEnvelopeVisitor.visit(geometry);
if (bbox.isPresent()) {
Rectangle envelope = bbox.get();
// Do stuff with the envelope
}
It is also possible to create the inner PointVisitor
separately, as well as use the visitor for multiple geometries.
PointVisitor pointVisitor = new CartesianPointVisitor();
SpatialEnvelopeVisitor visitor = new SpatialEnvelopeVisitor(pointVisitor);
for (Geometry geometry : geometries) {
geometry.visit(visitor);
}
if (visitor.isValid()) {
Rectangle envelope = visitor.getResult();
// Do stuff with the envelope
}
Code that wishes to modify the behaviour of the visitor can implement the PointVisitor
interface,
or extend the existing implementations.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The cartesian point visitor determines the envelope by the minimum and maximum x/y coordinates.static class
The geographic point visitor determines the envelope by the minimum and maximum x/y coordinates, while allowing for wrapping the longitude around the dateline.static interface
Visitor for visiting points and rectangles.static enum
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvisit
(GeometryCollection<?> collection) visit
(LinearRing ring) visit
(MultiPoint multiPoint) visit
(MultiPolygon multiPolygon) visitCartesian
(Geometry geometry) Determine the BBOX without considering the CRS or wrapping of the longitude.visitGeo
(Geometry geometry, SpatialEnvelopeVisitor.WrapLongitude wrapLongitude) Determine the BBOX assuming the CRS is geographic (eg WGS84) and optionally wrapping the longitude around the dateline.
-
Constructor Details
-
SpatialEnvelopeVisitor
-
-
Method Details
-
visitCartesian
Determine the BBOX without considering the CRS or wrapping of the longitude. Note that incoming BBOX's that do cross the dateline (minx>maxx) will be treated as invalid. -
visitGeo
public static Optional<Rectangle> visitGeo(Geometry geometry, SpatialEnvelopeVisitor.WrapLongitude wrapLongitude) Determine the BBOX assuming the CRS is geographic (eg WGS84) and optionally wrapping the longitude around the dateline. -
getResult
-
visit
- Specified by:
visit
in interfaceGeometryVisitor<Boolean,
RuntimeException> - Throws:
RuntimeException
-
visit
- Specified by:
visit
in interfaceGeometryVisitor<Boolean,
RuntimeException> - Throws:
RuntimeException
-
visit
- Specified by:
visit
in interfaceGeometryVisitor<Boolean,
RuntimeException> - Throws:
RuntimeException
-
visit
- Specified by:
visit
in interfaceGeometryVisitor<Boolean,
RuntimeException> - Throws:
RuntimeException
-
visit
- Specified by:
visit
in interfaceGeometryVisitor<Boolean,
RuntimeException> - Throws:
RuntimeException
-
visit
- Specified by:
visit
in interfaceGeometryVisitor<Boolean,
RuntimeException> - Throws:
RuntimeException
-
visit
- Specified by:
visit
in interfaceGeometryVisitor<Boolean,
RuntimeException> - Throws:
RuntimeException
-
visit
- Specified by:
visit
in interfaceGeometryVisitor<Boolean,
RuntimeException> - Throws:
RuntimeException
-
visit
- Specified by:
visit
in interfaceGeometryVisitor<Boolean,
RuntimeException> - Throws:
RuntimeException
-
visit
- Specified by:
visit
in interfaceGeometryVisitor<Boolean,
RuntimeException> - Throws:
RuntimeException
-