public final class LineString extends java.lang.Object implements CoordinateContainer<java.util.List<Point>>
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.
The list of points must be equal to or greater than 2. A LineString has non-zero length and zero area. It may approximate a curve and need not be straight. Unlike a LinearRing, a LineString is not closed.
When representing a LineString that crosses the antimeridian, interoperability is improved by modifying their geometry. Any geometry that crosses the antimeridian SHOULD be represented by cutting it in two such that neither part's representation crosses the antimeridian.
For example, a line extending from 45 degrees N, 170 degrees E across the antimeridian to 45 degrees N, 170 degrees W should be cut in two and represented as a MultiLineString.
A sample GeoJson LineString's provided below (in it's serialized state).
{ "TYPE": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ] }Look over the
Point
documentation to get more
information about formatting your list of point objects correctly.Modifier and Type | Method and Description |
---|---|
BoundingBox |
bbox()
A Feature Collection might have a member named
bbox to include information on the
coordinate range for it's Feature s. |
java.util.List<Point> |
coordinates()
Provides the list of
Point s that make up the LineString geometry. |
boolean |
equals(java.lang.Object obj) |
static LineString |
fromJson(java.lang.String json)
Create a new instance of this class by passing in a formatted valid JSON String.
|
static LineString |
fromLngLats(java.util.List<Point> points)
Create a new instance of this class by defining a list of
Point s which follow the
correct specifications described in the Point documentation. |
static LineString |
fromLngLats(java.util.List<Point> points,
BoundingBox bbox)
Create a new instance of this class by defining a list of
Point s which follow the
correct specifications described in the Point documentation. |
static LineString |
fromLngLats(MultiPoint multiPoint)
Create a new instance of this class by defining a
MultiPoint object and passing. |
static LineString |
fromLngLats(MultiPoint multiPoint,
BoundingBox bbox)
Create a new instance of this class by defining a
MultiPoint object and passing. |
static LineString |
fromPolyline(java.lang.String polyline,
int precision)
Create a new instance of this class by convert a polyline string into a lineString.
|
int |
hashCode() |
java.lang.String |
toJson()
This takes the currently defined values found inside this instance and converts it to a GeoJson
string.
|
java.lang.String |
toPolyline(int precision)
Encode this LineString into a Polyline string for easier serializing.
|
java.lang.String |
toString() |
java.lang.String |
type()
This describes the TYPE of GeoJson geometry this object is, thus this will always return
LineString . |
static com.google.gson.TypeAdapter<LineString> |
typeAdapter(com.google.gson.Gson gson)
Gson TYPE adapter for parsing Gson to this class.
|
public static LineString fromJson(java.lang.String json)
fromLngLats(List)
. For a valid lineString to exist, it must
have at least 2 coordinate entries. The LineString should also have non-zero distance and zero
area.json
- a formatted valid JSON string defining a GeoJson LineStringpublic static LineString fromLngLats(@NonNull MultiPoint multiPoint)
MultiPoint
object and passing. The
multipoint object should comply with the GeoJson specifications described in the documentation.multiPoint
- which will make up the LineString geometrypublic static LineString fromLngLats(@NonNull java.util.List<Point> points)
Point
s which follow the
correct specifications described in the Point documentation. Note that there should not be any
duplicate points inside the list and the points combined should create a LineString with a
distance greater than 0.
Note that if less than 2 points are passed in, a runtime exception will occur.
points
- a list of Point
s which make up the LineString geometrypublic static LineString fromLngLats(@NonNull java.util.List<Point> points, @Nullable BoundingBox bbox)
Point
s which follow the
correct specifications described in the Point documentation. Note that there should not be any
duplicate points inside the list and the points combined should create a LineString with a
distance greater than 0.
Note that if less than 2 points are passed in, a runtime exception will occur.
points
- a list of Point
s which make up the LineString geometrybbox
- optionally include a bbox definition as a double arraypublic static LineString fromLngLats(@NonNull MultiPoint multiPoint, @Nullable BoundingBox bbox)
MultiPoint
object and passing. The
multipoint object should comply with the GeoJson specifications described in the documentation.multiPoint
- which will make up the LineString geometrybbox
- optionally include a bbox definition as a double arraypublic static LineString fromPolyline(@NonNull java.lang.String polyline, int precision)
polyline
- encoded string geometry to decode into a new LineString instanceprecision
- The encoded precision which must match the same precision used when the string
was first encoded@NonNull public java.lang.String type()
LineString
.@Nullable public 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 java.util.List<Point> coordinates()
Point
s that make up the LineString geometry.coordinates
in interface CoordinateContainer<java.util.List<Point>>
public java.lang.String toJson()
public java.lang.String toPolyline(int precision)
precision
- the encoded precision which fits your best use-casepublic static com.google.gson.TypeAdapter<LineString> typeAdapter(com.google.gson.Gson gson)
gson
- the built Gson
objectpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object