Class Point
- All Implemented Interfaces:
CoordinateContainer<List<Double>>,GeoJson,Geometry,Serializable
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 TypeMethodDescriptiondoublealtitude()Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the coordinate array.bbox()A Feature Collection might have a member namedbboxto include information on the coordinate range for it'sFeatures.Provide a single double array containing the longitude, latitude, and optionally an altitude/elevation.booleanstatic PointCreate a new instance of this class by passing in a formatted valid JSON String.static PointfromLngLat(double longitude, double latitude) Create a new instance of this class defining a longitude and latitude value in that respective order.static PointfromLngLat(double longitude, double latitude, double altitude) Create a new instance of this class defining a longitude and latitude value in that respective order.static PointfromLngLat(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 PointfromLngLat(double longitude, double latitude, BoundingBox bbox) Create a new instance of this class defining a longitude and latitude value in that respective order.booleanOptionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the coordinate array.inthashCode()doublelatitude()This returns a double value representing the y or northing position of this point.doubleThis returns a double value representing the x or easting position of this point.toJson()This takes the currently defined values found inside this instance and converts it to a GeoJson string.toString()type()This describes the TYPE of GeoJson geometry this object is, thus this will always returnPoint.static com.google.gson.TypeAdapter<Point>typeAdapter(com.google.gson.Gson gson) Gson TYPE adapter for parsing Gson to this class.
-
Method Details
-
fromJson
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 asfromLngLat(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
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 pointlatitude- 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
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 pointlatitude- a double value representing the y position of this pointbbox- 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
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 pointlatitude- a double value representing the y position of this pointaltitude- 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 pointlatitude- a double value representing the y position of this pointaltitude- a double value which can be negative or positive infinity representing either elevation or altitudebbox- 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
This describes the TYPE of GeoJson geometry this object is, thus this will always returnPoint. -
bbox
A Feature Collection might have a member namedbboxto include information on the coordinate range for it'sFeatures. 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. -
coordinates
Provide a single double array containing the longitude, latitude, and optionally an altitude/elevation.longitude(),latitude(), andaltitude()are all avaliable which make getting specific coordinates more direct.- Specified by:
coordinatesin interfaceCoordinateContainer<List<Double>>- Returns:
- a double array which holds this points coordinates
- Since:
- 3.0.0
-
toJson
This takes the currently defined values found inside this instance and converts it to a GeoJson string. -
typeAdapter
Gson TYPE adapter for parsing Gson to this class.- Parameters:
gson- the builtGsonobject- Returns:
- the TYPE adapter for this class
- Since:
- 3.0.0
-
toString
-
equals
-
hashCode
public int hashCode()
-