Class BoundingBox

java.lang.Object
com.mapbox.geojson.BoundingBox
All Implemented Interfaces:
Serializable

public class BoundingBox extends Object implements Serializable
A GeoJson object MAY have a member named "bbox" to include information on the coordinate range for its Geometries, Features, or FeatureCollections.

This class simplifies the build process for creating a bounding box and working with them when deserialized. specific parameter naming helps define which coordinates belong where when a bounding box instance is being created. Note that since GeoJson objects only have the option of including a bounding box JSON element, the bbox value returned by a GeoJson object might be null.

At a minimum, a bounding box will have two Points or four coordinates which define the box. A 3rd dimensional bounding box can be produced if elevation or altitude is defined.

Since:
3.0.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    final double
    Convenience method for getting the bounding box most easterly point (longitude) as a double coordinate.
    boolean
     
    fromCoordinates(double west, double south, double east, double north)
    Deprecated.
    fromCoordinates(double west, double south, double southwestAltitude, double east, double north, double northEastAltitude)
    Deprecated.
    Create a new instance of this class by passing in a formatted valid JSON String.
    fromLngLats(double west, double south, double east, double north)
    Define a new instance of this class by passing in four coordinates in the same order they would appear in the serialized GeoJson form.
    fromLngLats(double west, double south, double southwestAltitude, double east, double north, double northEastAltitude)
    Define a new instance of this class by passing in four coordinates in the same order they would appear in the serialized GeoJson form.
    fromPoints(Point southwest, Point northeast)
    Define a new instance of this class by passing in two Points, representing both the southwest and northwest corners of the bounding box.
    int
     
    final double
    Convenience method for getting the bounding box most westerly point (longitude) as a double coordinate.
    Provides the Point which represents the northeast corner of this bounding box when the map is facing due north.
    final double
    Convenience method for getting the bounding box most southerly point (latitude) as a double coordinate.
    Provides the Point which represents the southwest corner of this bounding box when the map is facing due north.
    final String
    This takes the currently defined values found inside this instance and converts it to a GeoJson string.
     
    static com.google.gson.TypeAdapter<BoundingBox>
    typeAdapter(com.google.gson.Gson gson)
    Gson TYPE adapter for parsing Gson to this class.
    final double
    Convenience method for getting the bounding box most westerly point (longitude) as a double coordinate.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • fromJson

      public static BoundingBox fromJson(String json)
      Create a new instance of this class by passing in a formatted valid JSON String.
      Parameters:
      json - a formatted valid JSON string defining a Bounding Box
      Returns:
      a new instance of this class defined by the values passed inside this static factory method
      Since:
      3.0.0
    • fromPoints

      public static BoundingBox fromPoints(@NonNull Point southwest, @NonNull Point northeast)
      Define a new instance of this class by passing in two Points, representing both the southwest and northwest corners of the bounding box.
      Parameters:
      southwest - represents the bottom left corner of the bounding box when the camera is pointing due north
      northeast - represents the top right corner of the bounding box when the camera is pointing due north
      Returns:
      a new instance of this class defined by the provided points
      Since:
      3.0.0
    • fromCoordinates

      @Deprecated public static BoundingBox fromCoordinates(double west, double south, double east, double north)
      Deprecated.
      Define a new instance of this class by passing in four coordinates in the same order they would appear in the serialized GeoJson form. Limits are placed on the minimum and maximum coordinate values which can exist and comply with the GeoJson spec.
      Parameters:
      west - the left side of the bounding box when the map is facing due north
      south - the bottom side of the bounding box when the map is facing due north
      east - the right side of the bounding box when the map is facing due north
      north - the top side of the bounding box when the map is facing due north
      Returns:
      a new instance of this class defined by the provided coordinates
      Since:
      3.0.0
    • fromCoordinates

      @Deprecated public static BoundingBox fromCoordinates(double west, double south, double southwestAltitude, double east, double north, double northEastAltitude)
      Deprecated.
      Define a new instance of this class by passing in four coordinates in the same order they would appear in the serialized GeoJson form. Limits are placed on the minimum and maximum coordinate values which can exist and comply with the GeoJson spec.
      Parameters:
      west - the left side of the bounding box when the map is facing due north
      south - the bottom side of the bounding box when the map is facing due north
      southwestAltitude - the southwest corner altitude or elevation when the map is facing due north
      east - the right side of the bounding box when the map is facing due north
      north - the top side of the bounding box when the map is facing due north
      northEastAltitude - the northeast corner altitude or elevation when the map is facing due north
      Returns:
      a new instance of this class defined by the provided coordinates
      Since:
      3.0.0
    • fromLngLats

      public static BoundingBox fromLngLats(double west, double south, double east, double north)
      Define a new instance of this class by passing in four coordinates in the same order they would appear in the serialized GeoJson form. Limits are placed on the minimum and maximum coordinate values which can exist and comply with the GeoJson spec.
      Parameters:
      west - the left side of the bounding box when the map is facing due north
      south - the bottom side of the bounding box when the map is facing due north
      east - the right side of the bounding box when the map is facing due north
      north - the top side of the bounding box when the map is facing due north
      Returns:
      a new instance of this class defined by the provided coordinates
      Since:
      3.1.0
    • fromLngLats

      public static BoundingBox fromLngLats(double west, double south, double southwestAltitude, double east, double north, double northEastAltitude)
      Define a new instance of this class by passing in four coordinates in the same order they would appear in the serialized GeoJson form. Limits are placed on the minimum and maximum coordinate values which can exist and comply with the GeoJson spec.
      Parameters:
      west - the left side of the bounding box when the map is facing due north
      south - the bottom side of the bounding box when the map is facing due north
      southwestAltitude - the southwest corner altitude or elevation when the map is facing due north
      east - the right side of the bounding box when the map is facing due north
      north - the top side of the bounding box when the map is facing due north
      northEastAltitude - the northeast corner altitude or elevation when the map is facing due north
      Returns:
      a new instance of this class defined by the provided coordinates
      Since:
      3.1.0
    • southwest

      @NonNull public Point southwest()
      Provides the Point which represents the southwest corner of this bounding box when the map is facing due north.
      Returns:
      a Point which defines this bounding boxes southwest corner
      Since:
      3.0.0
    • northeast

      @NonNull public Point northeast()
      Provides the Point which represents the northeast corner of this bounding box when the map is facing due north.
      Returns:
      a Point which defines this bounding boxes northeast corner
      Since:
      3.0.0
    • west

      public final double west()
      Convenience method for getting the bounding box most westerly point (longitude) as a double coordinate.
      Returns:
      the most westerly coordinate inside this bounding box
      Since:
      3.0.0
    • south

      public final double south()
      Convenience method for getting the bounding box most southerly point (latitude) as a double coordinate.
      Returns:
      the most southerly coordinate inside this bounding box
      Since:
      3.0.0
    • east

      public final double east()
      Convenience method for getting the bounding box most easterly point (longitude) as a double coordinate.
      Returns:
      the most easterly coordinate inside this bounding box
      Since:
      3.0.0
    • north

      public final double north()
      Convenience method for getting the bounding box most westerly point (longitude) as a double coordinate.
      Returns:
      the most westerly coordinate inside this bounding box
      Since:
      3.0.0
    • typeAdapter

      public static com.google.gson.TypeAdapter<BoundingBox> typeAdapter(com.google.gson.Gson gson)
      Gson TYPE adapter for parsing Gson to this class.
      Parameters:
      gson - the built Gson object
      Returns:
      the TYPE adapter for this class
      Since:
      3.0.0
    • toJson

      public final String toJson()
      This takes the currently defined values found inside this instance and converts it to a GeoJson string.
      Returns:
      a JSON string which represents this Bounding box
      Since:
      3.0.0
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object