public final class GeoBoundingBox
extends java.lang.Object
Although a bounding box is specified by its top-left and bottom-right corner, the box is not necessarily the smallest rectangle spanned by these two points. It is possible to define geobounding boxes that are wider than 180 degrees or higher then 90 degrees (e.g. by setting the longitude of the top-left corner to a bigger value than the longitude of the bottom-right corner). Please note the top-left corner's latitude must be greater than or equal to bottom-right corner's latitude. Otherwise, the bounding box will be in invalid state.
For example, a geobounding box with longitude of -180 degrees for the top-left corner and a longitude of 180 degrees for the bottom-right corner will construct an area that encircles the globe, whereas a geobounding box with the same longitude value for both corners will construct an area with a width of 0 degrees.
Constructor and Description |
---|
GeoBoundingBox(GeoCoordinate center,
float height,
float width)
Creates a
GeoBoundingBox with a specified center and width and height in distance. |
GeoBoundingBox(GeoCoordinate topLeft,
GeoCoordinate bottomRight)
Creates a
GeoBoundingBox with specified top-left and bottom-right coordinates. |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(GeoBoundingBox bbox)
Determines whether the specified
GeoBoundingBox is covered entirely by this
GeoBoundingBox . |
boolean |
contains(GeoCoordinate coord)
Determines whether the specified
GeoCoordinate is contained within this
GeoBoundingBox . |
boolean |
equals(java.lang.Object other) |
GeoBoundingBox |
expand(float latitudeMeters,
float longitudeMeters)
Expands the
GeoBoundingBox by a fixed distance. |
GeoCoordinate |
getBottomRight()
Gets the current bottom-right coordinate of the
GeoBoundingBox . |
static GeoBoundingBox |
getBoundingBoxContainingGeoCoordinates(java.util.List<GeoCoordinate> coordinates)
Constructs a
GeoBoundingBox which contains all coordinates in an array. |
GeoCoordinate |
getCenter()
Gets the center
GeoCoordinate of the GeoBoundingBox . |
double |
getHeight()
Gets the current
GeoBoundingBox height, in degrees. |
GeoCoordinate |
getTopLeft()
Gets the current top-left coordinate of the
GeoBoundingBox . |
double |
getWidth()
Gets the current
GeoBoundingBox width, in degrees. |
int |
hashCode() |
boolean |
intersects(GeoBoundingBox bbox)
Determines whether the intersection of this
GeoBoundingBox instance and the specified
GeoBoundingBox is non-empty. |
boolean |
isEmpty()
Determines whether the size of the enclosed
GeoBoundingBox area is 0. |
GeoBoundingBox |
merge(GeoBoundingBox bbox)
Merges two
GeoBoundingBox objects by returning the smallest GeoBoundingBox
covering both this GeoBoundingBox and the specified GeoBoundingBox . |
static GeoBoundingBox |
mergeBoxes(java.util.List<GeoBoundingBox> bboxes)
Merges multiple
GeoBoundingBox objects by returning the smallest
GeoBoundingBox covering all specified GeoBoundingBox objects. |
GeoBoundingBox |
resizeToCenter(GeoCoordinate coord)
Returns a new box with the specified
GeoCoordinate located at the center. |
public GeoBoundingBox(GeoCoordinate topLeft, GeoCoordinate bottomRight)
GeoBoundingBox
with specified top-left and bottom-right coordinates.topLeft
- A GeoCoordinate
representing the top-left corner of the bounding boxbottomRight
- A GeoCoordinate
representing the bottom-right corner of the bounding boxjava.lang.IllegalArgumentException
- If the arguments constructs an invalid GeoBoundingBox
.public GeoBoundingBox(GeoCoordinate center, float height, float width)
GeoBoundingBox
with a specified center and width and height in distance.center
- A GeoCoordinate
representing the geographical center of the bounding box.height
- The geographical height in meterswidth
- The geographical width in meterspublic GeoCoordinate getTopLeft()
GeoBoundingBox
.GeoCoordinate
public GeoCoordinate getBottomRight()
GeoBoundingBox
.GeoCoordinate
public double getWidth()
GeoBoundingBox
width, in degrees.public double getHeight()
GeoBoundingBox
height, in degrees.public GeoBoundingBox merge(GeoBoundingBox bbox)
GeoBoundingBox
objects by returning the smallest GeoBoundingBox
covering both this GeoBoundingBox
and the specified GeoBoundingBox
.bbox
- A GeoBoundingBox
to merge with this GeoBoundingBox
GeoBoundingBox
that covers both of the merged
GeoBoundingBox
objectsmergeBoxes(List)
public static GeoBoundingBox mergeBoxes(java.util.List<GeoBoundingBox> bboxes)
GeoBoundingBox
objects by returning the smallest
GeoBoundingBox
covering all specified GeoBoundingBox
objects.bboxes
- A list of GeoBoundingBox
objects to mergeGeoBoundingBox
that covers all of the merged
GeoBoundingBox
objectsmerge(GeoBoundingBox)
public boolean contains(GeoBoundingBox bbox)
GeoBoundingBox
is covered entirely by this
GeoBoundingBox
.bbox
- A GeoBoundingBox
to check for containment within this
GeoBoundingBox
GeoBoundingBox
, false otherwisecontains(GeoCoordinate)
public boolean contains(GeoCoordinate coord)
GeoCoordinate
is contained within this
GeoBoundingBox
.coord
- A GeoCoordinate
to check for containment within this
GeoBoundingBox
GeoBoundingBox
, false otherwisecontains(GeoBoundingBox)
public static GeoBoundingBox getBoundingBoxContainingGeoCoordinates(java.util.List<GeoCoordinate> coordinates)
GeoBoundingBox
which contains all coordinates in an array.
The constructed GeoBoundingBox will be the smallest possible box which contains all the GeoCoordinate in the input array.
coordinates
- An array of GeoCoordinate
defining the new GeoBoundingBoxpublic boolean intersects(GeoBoundingBox bbox)
GeoBoundingBox
instance and the specified
GeoBoundingBox
is non-empty.bbox
- A GeoBoundingBox
to check for intersection with this
GeoBoundingBox
GeoBoundingBox
objects is non-empty, false
otherwisepublic boolean isEmpty()
GeoBoundingBox
area is 0.public GeoCoordinate getCenter()
GeoCoordinate
of the GeoBoundingBox
.GeoBoundingBox
public GeoBoundingBox resizeToCenter(GeoCoordinate coord)
GeoCoordinate
located at the center.coord
- A GeoCoordinate
that will become the center of the new
GeoBoundingBox
public GeoBoundingBox expand(float latitudeMeters, float longitudeMeters)
GeoBoundingBox
by a fixed distance.latitudeMeters
- The geographical height in meters to expand the GeoBoundingBox
longitudeMeters
- The geographical width in meters to expand the GeoBoundingBox
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object