public abstract class Point extends java.lang.Object implements CoordinateContainer<java.util.List<java.lang.Double>>, java.io.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 it's serialized state).
{ "TYPE": "Point", "coordinates": [100.0, 0.0] }
Constructor and Description |
---|
Point() |
Modifier and Type | Method and Description |
---|---|
double |
altitude()
Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the
coordinate array.
|
abstract BoundingBox |
bbox()
A Feature Collection might have a member named
bbox to include information on the
coordinate range for it's Feature s. |
abstract java.util.List<java.lang.Double> |
coordinates()
Provide a single double array containing the longitude, latitude, and optionally an
altitude/elevation.
|
static Point |
fromJson(java.lang.String json)
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,
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,
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.
|
boolean |
hasAltitude()
Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the
coordinate array.
|
double |
latitude()
This returns a double value ranging from -90 to 90 representing the y or northing position of
this point.
|
double |
longitude()
This returns a double value ranging from -180 to 180 representing the x or easting position of
this point.
|
java.lang.String |
toJson()
This takes the currently defined values found inside this instance and converts it to a GeoJson
string.
|
abstract java.lang.String |
type()
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.
|
public static Point fromJson(@NonNull java.lang.String json)
fromLngLat(double, double)
. Longitude values should not exceed
the spec defined -180 to 180 range and latitude's limit of -90 to 90. 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.json
- a formatted valid JSON string defining a GeoJson Pointpublic static Point fromLngLat(double longitude, double latitude)
longitude
- a double value between -180 to 180 representing the x position of this pointlatitude
- a double value between -90 to 90 representing the y position of this pointpublic static Point fromLngLat(double longitude, double latitude, @Nullable BoundingBox bbox)
longitude
- a double value between -180 to 180 representing the x position of this pointlatitude
- a double value between -90 to 90 representing the y position of this pointbbox
- optionally include a bbox definition as a double arraypublic static Point fromLngLat(double longitude, double latitude, double altitude)
longitude
- a double value between -180 to 180 representing the x position of this pointlatitude
- a double value between -90 to 90 representing the y position of this pointaltitude
- a double value which can be negative or positive infinity representing either
elevation or altitudepublic static Point fromLngLat(double longitude, double latitude, double altitude, @Nullable BoundingBox bbox)
longitude
- a double value between -180 to 180 representing the x position of this pointlatitude
- a double value between -90 to 90 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 arraypublic double longitude()
public double latitude()
public double altitude()
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.public boolean hasAltitude()
@NonNull public abstract java.lang.String type()
Point
.@Nullable public abstract BoundingBox bbox()
bbox
to include information on the
coordinate range for it's Feature
s. 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.@NonNull public abstract java.util.List<java.lang.Double> coordinates()
longitude()
, latitude()
, and altitude()
are all
avaliable which make getting specific coordinates more direct.coordinates
in interface CoordinateContainer<java.util.List<java.lang.Double>>
public java.lang.String toJson()
public static com.google.gson.TypeAdapter<Point> typeAdapter(com.google.gson.Gson gson)
gson
- the built Gson
object