Class SpatialEnvelopeVisitor

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.
Usage of this is as simple as: 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.