Class Point

java.lang.Object
com.mapbox.geojson.Point
All Implemented Interfaces:
CoordinateContainer<List<Double>>, GeoJson, Geometry, Serializable

public final class Point extends Object implements CoordinateContainer<List<Double>>
A point represents a single geographic position and is one of the seven Geometries found in the GeoJson spec.

This adheres to the RFC 7946 internet standard when serialized into JSON. When deserialized, this class becomes an immutable object which should be initiated using its static factory methods.

Coordinates are in x, y order (easting, northing for projected coordinates), longitude, and latitude for geographic coordinates), precisely in that order and using double values. Altitude or elevation MAY be included as an optional third parameter while creating this object.

The size of a GeoJson text in bytes is a major interoperability consideration, and precision of coordinate values has a large impact on the size of texts when serialized. For geographic coordinates with units of degrees, 6 decimal places (a default common in, e.g., sprintf) amounts to about 10 centimeters, a precision well within that of current GPS systems. Implementations should consider the cost of using a greater precision than necessary.

Furthermore, pertaining to altitude, the WGS 84 datum is a relatively coarse approximation of the geoid, with the height varying by up to 5 m (but generally between 2 and 3 meters) higher or lower relative to a surface parallel to Earth's mean sea level.

A sample GeoJson Point's provided below (in its serialized state).

 {
   "type": "Point",
   "coordinates": [100.0, 0.0]
 }
 
Since:
1.0.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the coordinate array.
    A Feature Collection might have a member named bbox to include information on the coordinate range for it's Features.
    Provide a single double array containing the longitude, latitude, and optionally an altitude/elevation.
    boolean
     
    static Point
    Create a new instance of this class by passing in a formatted valid JSON String.
    static Point
    fromLngLat(double longitude, double latitude)
    Create a new instance of this class defining a longitude and latitude value in that respective order.
    static Point
    fromLngLat(double longitude, double latitude, double altitude)
    Create a new instance of this class defining a longitude and latitude value in that respective order.
    static Point
    fromLngLat(double longitude, double latitude, double altitude, BoundingBox bbox)
    Create a new instance of this class defining a longitude and latitude value in that respective order.
    static Point
    fromLngLat(double longitude, double latitude, BoundingBox bbox)
    Create a new instance of this class defining a longitude and latitude value in that respective order.
    boolean
    Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the coordinate array.
    int
     
    double
    This returns a double value representing the y or northing position of this point.
    double
    This returns a double value representing the x or easting position of this point.
    This takes the currently defined values found inside this instance and converts it to a GeoJson string.
     
    This describes the TYPE of GeoJson geometry this object is, thus this will always return Point.
    static com.google.gson.TypeAdapter<Point>
    typeAdapter(com.google.gson.Gson gson)
    Gson TYPE adapter for parsing Gson to this class.

    Methods inherited from class java.lang.Object

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

    • fromJson

      public static Point fromJson(@NonNull String json)
      Create a new instance of this class by passing in a formatted valid JSON String. If you are creating a Point object from scratch it is better to use one of the other provided static factory methods such as fromLngLat(double, double). While no limit is placed on decimal precision, for performance reasons when serializing and deserializing it is suggested to limit decimal precision to within 6 decimal places.
      Parameters:
      json - a formatted valid JSON string defining a GeoJson Point
      Returns:
      a new instance of this class defined by the values passed inside this static factory method
      Since:
      1.0.0
    • fromLngLat

      public static Point fromLngLat(double longitude, double latitude)
      Create a new instance of this class defining a longitude and latitude value in that respective order. While no limit is placed on decimal precision, for performance reasons when serializing and deserializing it is suggested to limit decimal precision to within 6 decimal places.
      Parameters:
      longitude - a double value representing the x position of this point
      latitude - a double value representing the y position of this point
      Returns:
      a new instance of this class defined by the values passed inside this static factory method
      Since:
      3.0.0
    • fromLngLat

      public static Point fromLngLat(double longitude, double latitude, @Nullable BoundingBox bbox)
      Create a new instance of this class defining a longitude and latitude value in that respective order. While no limit is placed on decimal precision, for performance reasons when serializing and deserializing it is suggested to limit decimal precision to within 6 decimal places. An optional altitude value can be passed in and can vary between negative infinity and positive infinity.
      Parameters:
      longitude - a double value representing the x position of this point
      latitude - a double value representing the y position of this point
      bbox - optionally include a bbox definition as a double array
      Returns:
      a new instance of this class defined by the values passed inside this static factory method
      Since:
      3.0.0
    • fromLngLat

      public static Point fromLngLat(double longitude, double latitude, double altitude)
      Create a new instance of this class defining a longitude and latitude value in that respective order. While no limit is placed on decimal precision, for performance reasons when serializing and deserializing it is suggested to limit decimal precision to within 6 decimal places. An optional altitude value can be passed in and can vary between negative infinity and positive infinity.
      Parameters:
      longitude - a double value representing the x position of this point
      latitude - a double value representing the y position of this point
      altitude - a double value which can be negative or positive infinity representing either elevation or altitude
      Returns:
      a new instance of this class defined by the values passed inside this static factory method
      Since:
      3.0.0
    • fromLngLat

      public static Point fromLngLat(double longitude, double latitude, double altitude, @Nullable BoundingBox bbox)
      Create a new instance of this class defining a longitude and latitude value in that respective order. While no limit is placed on decimal precision, for performance reasons when serializing and deserializing it is suggested to limit decimal precision to within 6 decimal places. An optional altitude value can be passed in and can vary between negative infinity and positive infinity.
      Parameters:
      longitude - a double value representing the x position of this point
      latitude - a double value representing the y position of this point
      altitude - a double value which can be negative or positive infinity representing either elevation or altitude
      bbox - optionally include a bbox definition as a double array
      Returns:
      a new instance of this class defined by the values passed inside this static factory method
      Since:
      3.0.0
    • longitude

      public double longitude()
      This returns a double value representing the x or easting position of this point. ideally, this value would be restricted to 6 decimal places to correctly follow the GeoJson spec.
      Returns:
      a double value representing the x or easting position of this point
      Since:
      3.0.0
    • latitude

      public double latitude()
      This returns a double value representing the y or northing position of this point. ideally, this value would be restricted to 6 decimal places to correctly follow the GeoJson spec.
      Returns:
      a double value representing the y or northing position of this point
      Since:
      3.0.0
    • altitude

      public double altitude()
      Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the coordinate array. hasAltitude() can be used to determine if this value was set during initialization of this Point instance. This double value should only be used to represent either the elevation or altitude value at this particular point.
      Returns:
      a double value ranging from negative to positive infinity
      Since:
      3.0.0
    • hasAltitude

      public boolean hasAltitude()
      Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the coordinate array. If an altitude value was provided while initializing this instance, this will return true.
      Returns:
      true if this instance of point contains an altitude value
      Since:
      3.0.0
    • type

      @NonNull public String type()
      This describes the TYPE of GeoJson geometry this object is, thus this will always return Point.
      Specified by:
      type in interface GeoJson
      Returns:
      a String which describes the TYPE of geometry, for this object it will always return Point
      Since:
      1.0.0
    • bbox

      @Nullable public BoundingBox bbox()
      A Feature Collection might have a member named bbox to include information on the coordinate range for it's Features. The value of the bbox member MUST be a list of size 2*n where n is the number of dimensions represented in the contained feature geometries, with all axes of the most southwesterly point followed by all axes of the more northeasterly point. The axes order of a bbox follows the axes order of geometries.
      Specified by:
      bbox in interface GeoJson
      Returns:
      a list of double coordinate values describing a bounding box
      Since:
      3.0.0
    • coordinates

      @NonNull public List<Double> coordinates()
      Provide a single double array containing the longitude, latitude, and optionally an altitude/elevation. longitude(), latitude(), and altitude() are all avaliable which make getting specific coordinates more direct.
      Specified by:
      coordinates in interface CoordinateContainer<List<Double>>
      Returns:
      a double array which holds this points coordinates
      Since:
      3.0.0
    • toJson

      public String toJson()
      This takes the currently defined values found inside this instance and converts it to a GeoJson string.
      Specified by:
      toJson in interface GeoJson
      Returns:
      a JSON string which represents this Point geometry
      Since:
      1.0.0
    • typeAdapter

      public static com.google.gson.TypeAdapter<Point> 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
    • 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