Class LineString
- java.lang.Object
-
- com.mapbox.geojson.LineString
-
- All Implemented Interfaces:
CoordinateContainer<java.util.List<Point>>,GeoJson,Geometry,java.io.Serializable
public final class LineString extends java.lang.Object implements CoordinateContainer<java.util.List<Point>>
A linestring represents two or more geographic points that share a relationship 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.
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 thePointdocumentation to get more information about formatting your list of point objects correctly.- Since:
- 1.0.0
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BoundingBoxbbox()A Feature Collection might have a member namedbboxto include information on the coordinate range for it'sFeatures.java.util.List<Point>coordinates()Provides the list ofPoints that make up the LineString geometry.booleanequals(java.lang.Object obj)static LineStringfromJson(java.lang.String json)Create a new instance of this class by passing in a formatted valid JSON String.static LineStringfromLngLats(MultiPoint multiPoint)Create a new instance of this class by defining aMultiPointobject and passing.static LineStringfromLngLats(MultiPoint multiPoint, BoundingBox bbox)Create a new instance of this class by defining aMultiPointobject and passing.static LineStringfromLngLats(java.util.List<Point> points)Create a new instance of this class by defining a list ofPoints which follow the correct specifications described in the Point documentation.static LineStringfromLngLats(java.util.List<Point> points, BoundingBox bbox)Create a new instance of this class by defining a list ofPoints which follow the correct specifications described in the Point documentation.static LineStringfromPolyline(java.lang.String polyline, int precision)Create a new instance of this class by convert a polyline string into a lineString.inthashCode()java.lang.StringtoJson()This takes the currently defined values found inside this instance and converts it to a GeoJson string.java.lang.StringtoPolyline(int precision)Encode this LineString into a Polyline string for easier serializing.java.lang.StringtoString()java.lang.Stringtype()This describes the TYPE of GeoJson geometry this object is, thus this will always returnLineString.static com.google.gson.TypeAdapter<LineString>typeAdapter(com.google.gson.Gson gson)Gson TYPE adapter for parsing Gson to this class.
-
-
-
Method Detail
-
fromJson
public static LineString fromJson(java.lang.String json)
Create a new instance of this class by passing in a formatted valid JSON String. If you are creating a LineString object from scratch it is better to use one of the other provided static factory methods such asfromLngLats(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.- Parameters:
json- a formatted valid JSON string defining a GeoJson LineString- Returns:
- a new instance of this class defined by the values passed inside this static factory method
- Since:
- 1.0.0
-
fromLngLats
public static LineString fromLngLats(@NonNull MultiPoint multiPoint)
Create a new instance of this class by defining aMultiPointobject and passing. The multipoint object should comply with the GeoJson specifications described in the documentation.- Parameters:
multiPoint- which will make up the LineString geometry- Returns:
- a new instance of this class defined by the values passed inside this static factory method
- Since:
- 3.0.0
-
fromLngLats
public static LineString fromLngLats(@NonNull java.util.List<Point> points)
Create a new instance of this class by defining a list ofPoints 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.
- Parameters:
points- a list ofPoints which make up the LineString geometry- Returns:
- a new instance of this class defined by the values passed inside this static factory method
- Since:
- 3.0.0
-
fromLngLats
public static LineString fromLngLats(@NonNull java.util.List<Point> points, @Nullable BoundingBox bbox)
Create a new instance of this class by defining a list ofPoints 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.
- Parameters:
points- a list ofPoints which make up the LineString geometrybbox- 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
-
fromLngLats
public static LineString fromLngLats(@NonNull MultiPoint multiPoint, @Nullable BoundingBox bbox)
Create a new instance of this class by defining aMultiPointobject and passing. The multipoint object should comply with the GeoJson specifications described in the documentation.- Parameters:
multiPoint- which will make up the LineString geometrybbox- 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
-
fromPolyline
public static LineString fromPolyline(@NonNull java.lang.String polyline, int precision)
Create a new instance of this class by convert a polyline string into a lineString. This is handy when an API provides you with an encoded string representing the line geometry and you'd like to convert it to a useful LineString object. Note that the precision that the string geometry was encoded with needs to be known and passed into this method using the precision parameter.- Parameters:
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- Returns:
- a new instance of this class defined by the values passed inside this static factory method
- Since:
- 1.0.0
-
type
@NonNull public java.lang.String type()
This describes the TYPE of GeoJson geometry this object is, thus this will always returnLineString.
-
bbox
@Nullable public BoundingBox 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
@NonNull public java.util.List<Point> coordinates()
Provides the list ofPoints that make up the LineString geometry.- Specified by:
coordinatesin interfaceCoordinateContainer<java.util.List<Point>>- Returns:
- a list of points
- Since:
- 3.0.0
-
toJson
public java.lang.String toJson()
This takes the currently defined values found inside this instance and converts it to a GeoJson string.
-
toPolyline
public java.lang.String toPolyline(int precision)
Encode this LineString into a Polyline string for easier serializing. When passing geometry information over a mobile network connection, encoding the geometry first will generally result in less bandwidth usage.- Parameters:
precision- the encoded precision which fits your best use-case- Returns:
- a string describing the geometry of this LineString
- Since:
- 1.0.0
-
typeAdapter
public static com.google.gson.TypeAdapter<LineString> typeAdapter(com.google.gson.Gson gson)
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-