Class BoundingBox


  • public class BoundingBox
    extends Object
    Bounding Box with longitude and latitude ranges in degrees
    Author:
    osbornb
    • Constructor Detail

      • BoundingBox

        public BoundingBox()
        Constructor
      • BoundingBox

        public BoundingBox​(double minLongitude,
                           double minLatitude,
                           double maxLongitude,
                           double maxLatitude)
        Constructor
        Parameters:
        minLongitude - min longitude
        minLatitude - min latitude
        maxLongitude - max longitude
        maxLatitude - max latitude
        Since:
        2.0.0
      • BoundingBox

        public BoundingBox​(BoundingBox boundingBox)
        Constructor
        Parameters:
        boundingBox - bounding box
        Since:
        1.1.6
      • BoundingBox

        public BoundingBox​(GeometryEnvelope envelope)
        Constructor
        Parameters:
        envelope - geometry envelope
        Since:
        2.0.0
      • BoundingBox

        public BoundingBox​(Geometry geometry)
        Constructor
        Parameters:
        geometry - geometry
        Since:
        6.2.0
    • Method Detail

      • worldWGS84

        public static BoundingBox worldWGS84()
        Create a new WGS84 bounding box with world bounds (degrees)
        Returns:
        new bounding box
        Since:
        6.2.0
      • worldWebMercator

        public static BoundingBox worldWebMercator()
        Create a new Web Mercator bounding box with world bounds (meters)
        Returns:
        new bounding box
        Since:
        6.2.0
      • worldWGS84WithWebMercatorLimits

        public static BoundingBox worldWGS84WithWebMercatorLimits()
        Create a new WGS84 bounding box bounded by Web Mercator limits
        Returns:
        new bounding box
        Since:
        6.6.0
      • getMinLongitude

        public double getMinLongitude()
        Get the min longitude
        Returns:
        min longitude
      • setMinLongitude

        public void setMinLongitude​(double minLongitude)
        Set the min longitude
        Parameters:
        minLongitude - min longitude
      • getMaxLongitude

        public double getMaxLongitude()
        Get the max longitude
        Returns:
        max longitude
      • setMaxLongitude

        public void setMaxLongitude​(double maxLongitude)
        Set the max longitude
        Parameters:
        maxLongitude - max longitude
      • getMinLatitude

        public double getMinLatitude()
        Get the min latitude
        Returns:
        min latitude
      • setMinLatitude

        public void setMinLatitude​(double minLatitude)
        Set the min latitude
        Parameters:
        minLatitude - min latitude
      • getMaxLatitude

        public double getMaxLatitude()
        Get the max latitude
        Returns:
        max latitude
      • setMaxLatitude

        public void setMaxLatitude​(double maxLatitude)
        Set the max latitude
        Parameters:
        maxLatitude - max latitude
      • getLongitudeRange

        public double getLongitudeRange()
        Get the longitude range
        Returns:
        longitude range
        Since:
        3.5.0
      • getLatitudeRange

        public double getLatitudeRange()
        Get the latitude range
        Returns:
        latitude range
        Since:
        3.5.0
      • getCentroid

        public Point getCentroid()
        Get the bounding box centroid point
        Returns:
        centroid point
        Since:
        6.2.0
      • getCentroid

        public static Point getCentroid​(BoundingBox boundingBox)
        Get the bounding box centroid point
        Parameters:
        boundingBox - bounding box
        Returns:
        centroid point
        Since:
        6.2.0
      • getCentroid

        public Point getCentroid​(Projection projection)
        Get the centroid for the bounding box and projection
        Parameters:
        projection - projection of the bounding box
        Returns:
        centroid point
        Since:
        6.2.0
      • getCentroid

        public static Point getCentroid​(BoundingBox boundingBox,
                                        Projection projection)
        Get the centroid for the bounding box and projection
        Parameters:
        boundingBox - bounding box
        projection - projection of the bounding box
        Returns:
        centroid point
        Since:
        6.2.0
      • getDegreesCentroid

        public Point getDegreesCentroid()
        Get the centroid for the bounding box in degrees
        Returns:
        centroid point
        Since:
        6.2.0
      • getDegreesCentroid

        public static Point getDegreesCentroid​(BoundingBox boundingBox)
        Get the centroid for a bounding box in degrees
        Parameters:
        boundingBox - bounding box in degrees
        Returns:
        centroid point
        Since:
        6.2.0
      • buildEnvelope

        public GeometryEnvelope buildEnvelope()
        Build a Geometry Envelope from the bounding box
        Returns:
        geometry envelope
        Since:
        1.1.0
      • buildEnvelope

        public static GeometryEnvelope buildEnvelope​(BoundingBox boundingBox)
        Build a Geometry Envelope from the bounding box
        Parameters:
        boundingBox - bounding box
        Returns:
        geometry envelope
        Since:
        3.2.0
      • buildGeometry

        public Geometry buildGeometry()
        Build a geometry representation of the bounding box
        Returns:
        geometry, polygon or point
        Since:
        6.2.0
      • buildGeometry

        public static Geometry buildGeometry​(BoundingBox boundingBox)
        Build a geometry representation of the bounding box
        Parameters:
        boundingBox - bounding box
        Returns:
        geometry, polygon or point
        Since:
        6.2.0
      • complementary

        public BoundingBox complementary​(double maxProjectionLongitude)
        If the bounding box spans the Anti-Meridian, attempt to get a complementary bounding box using the max longitude of the unit projection
        Parameters:
        maxProjectionLongitude - max longitude of the world for the current bounding box units
        Returns:
        complementary bounding box or nil if none
        Since:
        2.0.0
      • complementaryWgs84

        public BoundingBox complementaryWgs84()
        If the bounding box spans the Anti-Meridian, attempt to get a complementary WGS84 bounding box
        Returns:
        complementary bounding box or nil if none
        Since:
        2.0.0
      • complementaryWebMercator

        public BoundingBox complementaryWebMercator()
        If the bounding box spans the Anti-Meridian, attempt to get a complementary Web Mercator bounding box
        Returns:
        complementary bounding box or nil if none
        Since:
        2.0.0
      • boundCoordinates

        public BoundingBox boundCoordinates​(double maxProjectionLongitude)
        Bound the bounding box longitudes within the min and max possible projection values. This may result in a max longitude numerically lower than the min longitude.
        Parameters:
        maxProjectionLongitude - max longitude of the world for the current bounding box units
        Returns:
        bounded bounding box
        Since:
        2.0.0
      • boundWgs84Coordinates

        public BoundingBox boundWgs84Coordinates()
        Bound the bounding box coordinates within WGS84 range values
        Returns:
        bounded bounding box
        Since:
        2.0.0
      • boundWebMercatorCoordinates

        public BoundingBox boundWebMercatorCoordinates()
        Bound the bounding box coordinates within Web Mercator range values
        Returns:
        bounded bounding box
        Since:
        2.0.0
      • expandCoordinates

        public BoundingBox expandCoordinates​(double maxProjectionLongitude)
        Expand the bounding box max longitude above the max possible projection value if needed to create a bounding box where the max longitude is numerically larger than the min longitude.
        Parameters:
        maxProjectionLongitude - max longitude of the world for the current bounding box units
        Returns:
        expanded bounding box
        Since:
        2.0.0
      • expandWgs84Coordinates

        public BoundingBox expandWgs84Coordinates()
        Expand the bounding box max longitude above the max WGS84 projection value if needed to create a bounding box where the max longitude is numerically larger than the min longitude.
        Returns:
        expanded bounding box
        Since:
        2.0.0
      • expandWebMercatorCoordinates

        public BoundingBox expandWebMercatorCoordinates()
        Expand the bounding box max longitude above the max Web Mercator projection value if needed to create a bounding box where the max longitude is numerically larger than the min longitude.
        Returns:
        expanded bounding box
        Since:
        2.0.0
      • transform

        public BoundingBox transform​(ProjectionTransform transform)
        Transform the bounding box using the provided projection transform
        Parameters:
        transform - projection transform
        Returns:
        transformed bounding box
        Since:
        3.0.0
      • transform

        public BoundingBox transform​(GeometryTransform transform)
        Transform the bounding box using the provided projection transform
        Parameters:
        transform - geometry transform
        Returns:
        transformed bounding box
        Since:
        6.0.0
      • intersects

        public boolean intersects​(BoundingBox boundingBox)
        Determine if intersects with the provided bounding box
        Parameters:
        boundingBox - bounding box
        Returns:
        true if intersects
        Since:
        3.1.0
      • intersects

        public boolean intersects​(BoundingBox boundingBox,
                                  boolean allowEmpty)
        Determine if intersects with the provided bounding box
        Parameters:
        boundingBox - bounding box
        allowEmpty - allow empty ranges when determining intersection
        Returns:
        true if intersects
        Since:
        3.1.0
      • overlap

        public BoundingBox overlap​(BoundingBox boundingBox)
        Get the overlapping bounding box with the provided bounding box
        Parameters:
        boundingBox - bounding box
        Returns:
        bounding box
        Since:
        3.1.0
      • overlap

        public BoundingBox overlap​(BoundingBox boundingBox,
                                   boolean allowEmpty)
        Get the overlapping bounding box with the provided bounding box
        Parameters:
        boundingBox - bounding box
        allowEmpty - allow empty ranges when determining overlap
        Returns:
        bounding box
        Since:
        3.1.0
      • union

        public BoundingBox union​(BoundingBox boundingBox)
        Get the union bounding box with the provided bounding box
        Parameters:
        boundingBox - bounding box
        Returns:
        bounding box
        Since:
        3.1.0
      • contains

        public boolean contains​(BoundingBox boundingBox)
        Determine if inclusively contains the provided bounding box
        Parameters:
        boundingBox - bounding box
        Returns:
        true if contains
        Since:
        3.1.0
      • squareExpand

        public BoundingBox squareExpand()
        Expand the bounding box to an equally sized width and height bounding box
        Returns:
        new square expanded bounding box
        Since:
        3.5.0
      • squareExpand

        public BoundingBox squareExpand​(double bufferPercentage)
        Expand the bounding box to an equally sized width and height bounding box with optional empty edge buffer
        Parameters:
        bufferPercentage - bounding box edge buffer percentage. A value of 0.1 adds a 10% buffer on each side of the squared bounding box.
        Returns:
        new square expanded bounding box
        Since:
        3.5.0
      • isPoint

        public boolean isPoint()
        Determine if the bounding box is of a single point
        Returns:
        true if a single point bounds
        Since:
        3.5.0
      • copy

        public BoundingBox copy()
        Copy the bounding box
        Returns:
        bounding box copy
        Since:
        6.2.0
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object