public final class Polygon extends java.lang.Object implements CoordinateContainer<java.util.List<java.util.List<Point>>>
To specify a constraint specific to Polygons, it is useful to introduce the concept of a linear ring:
RuntimeException
will
occur.
Though a linear ring is not explicitly represented as a GeoJson geometry TYPE, it leads to a canonical formulation of the Polygon geometry TYPE. When initializing a new instance of this class, a LineString for the outer and optionally an inner are checked to ensure a valid linear ring.
An example of a serialized polygon with no holes is given below:
{ "TYPE": "Polygon", "coordinates": [ [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]] ] }
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<java.util.List<Point>> |
coordinates()
Provides the list of
Point s that make up the Polygon geometry. |
boolean |
equals(java.lang.Object obj) |
static Polygon |
fromJson(java.lang.String json)
Create a new instance of this class by passing in a formatted valid JSON String.
|
static Polygon |
fromLngLats(java.util.List<java.util.List<Point>> coordinates)
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 Polygon |
fromLngLats(java.util.List<java.util.List<Point>> coordinates,
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 Polygon |
fromOuterInner(LineString outer,
BoundingBox bbox,
LineString... inner)
Create a new instance of this class by passing in an outer
LineString and optionally
one or more inner LineStrings. |
static Polygon |
fromOuterInner(LineString outer,
BoundingBox bbox,
java.util.List<LineString> inner)
Create a new instance of this class by passing in an outer
LineString and optionally
one or more inner LineStrings contained within a list. |
static Polygon |
fromOuterInner(LineString outer,
LineString... inner)
Create a new instance of this class by passing in an outer
LineString and optionally
one or more inner LineStrings. |
static Polygon |
fromOuterInner(LineString outer,
java.util.List<LineString> inner)
Create a new instance of this class by passing in an outer
LineString and optionally
one or more inner LineStrings contained within a list. |
int |
hashCode() |
java.util.List<LineString> |
inner()
Convenience method to get a list of inner
LineString s defining holes inside the
polygon. |
LineString |
outer()
Convenience method to get the outer
LineString which defines the outer perimeter of
the polygon. |
java.lang.String |
toJson()
This takes the currently defined values found inside this instance and converts it to a GeoJson
string.
|
java.lang.String |
toString() |
java.lang.String |
type()
This describes the TYPE of GeoJson geometry this object is, thus this will always return
Polygon . |
static com.google.gson.TypeAdapter<Polygon> |
typeAdapter(com.google.gson.Gson gson)
Gson TYPE adapter for parsing Gson to this class.
|
public static Polygon fromJson(@NonNull java.lang.String json)
fromOuterInner(LineString, LineString...)
. For a valid
For a valid Polygon to exist, it must follow the linear ring rules and the first list of
coordinates are considered the outer ring by default.json
- a formatted valid JSON string defining a GeoJson Polygonpublic static Polygon fromLngLats(@NonNull java.util.List<java.util.List<Point>> coordinates)
Point
s which follow the
correct specifications described in the Point documentation. Note that the first and last point
in the list should be the same enclosing the linear ring.coordinates
- a list of a list of points which represent the polygon geometrypublic static Polygon fromLngLats(@NonNull java.util.List<java.util.List<Point>> coordinates, @Nullable BoundingBox bbox)
Point
s which follow the
correct specifications described in the Point documentation. Note that the first and last point
in the list should be the same enclosing the linear ring.coordinates
- a list of a list of points which represent the polygon geometrybbox
- optionally include a bbox definition as a double arraypublic static Polygon fromOuterInner(@NonNull LineString outer, @Nullable LineString... inner)
LineString
and optionally
one or more inner LineStrings. Each of these LineStrings should follow the linear ring rules.
Note that if a LineString breaks one of the linear ring rules, a RuntimeException
will
be thrown.
outer
- a LineString which defines the outer perimeter of the polygoninner
- one or more LineStrings representing holes inside the outer perimeterpublic static Polygon fromOuterInner(@NonNull LineString outer, @Nullable BoundingBox bbox, @Nullable LineString... inner)
LineString
and optionally
one or more inner LineStrings. Each of these LineStrings should follow the linear ring rules.
Note that if a LineString breaks one of the linear ring rules, a RuntimeException
will
be thrown.
outer
- a LineString which defines the outer perimeter of the polygonbbox
- optionally include a bbox definition as a double arrayinner
- one or more LineStrings representing holes inside the outer perimeterpublic static Polygon fromOuterInner(@NonNull LineString outer, @Nullable java.util.List<LineString> inner)
LineString
and optionally
one or more inner LineStrings contained within a list. Each of these LineStrings should follow
the linear ring rules.
Note that if a LineString breaks one of the linear ring rules, a RuntimeException
will
be thrown.
outer
- a LineString which defines the outer perimeter of the polygoninner
- one or more LineStrings inside a list representing holes inside the outer
perimeterpublic static Polygon fromOuterInner(@NonNull LineString outer, @Nullable BoundingBox bbox, @Nullable java.util.List<LineString> inner)
LineString
and optionally
one or more inner LineStrings contained within a list. Each of these LineStrings should follow
the linear ring rules.
Note that if a LineString breaks one of the linear ring rules, a RuntimeException
will
be thrown.
outer
- a LineString which defines the outer perimeter of the polygonbbox
- optionally include a bbox definition as a double arrayinner
- one or more LineStrings inside a list representing holes inside the outer
perimeter@Nullable public LineString outer()
LineString
which defines the outer perimeter of
the polygon.LineString
defining the outer perimeter of this polygon@Nullable public java.util.List<LineString> inner()
LineString
s defining holes inside the
polygon. It is not guaranteed that this instance of Polygon contains holes and thus, might
return a null or empty list.LineString
s defining holes inside the polygon@NonNull public java.lang.String type()
Polygon
.@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<java.util.List<Point>> coordinates()
Point
s that make up the Polygon geometry. The first list holds the
different LineStrings, first being the outer ring and the following entries being inner holes
(if they exist).coordinates
in interface CoordinateContainer<java.util.List<java.util.List<Point>>>
public java.lang.String toJson()
public static com.google.gson.TypeAdapter<Polygon> 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