Class Polygon
- All Implemented Interfaces:
CoordinateContainer<List<List<Point>>>,GeoJson,Geometry,Serializable
To specify a constraint specific to Polygons, it is useful to introduce the concept of a linear ring:
- A linear ring is a closed LineString with four or more coordinates.
- The first and last coordinates are equivalent, and they MUST contain identical values; their representation SHOULD also be identical.
- A linear ring is the boundary of a surface or the boundary of a hole in a surface.
- A linear ring MUST follow the right-hand rule with respect to the area it bounds, i.e., exterior rings are counterclockwise, and holes are clockwise.
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]]
]
}
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbbox()A Feature Collection might have a member namedbboxto include information on the coordinate range for it'sFeatures.Provides the list ofPoints that make up the Polygon geometry.booleanstatic PolygonCreate a new instance of this class by passing in a formatted valid JSON String.static PolygonfromLngLats(List<List<Point>> coordinates) Create a new instance of this class by defining a list ofPoints which follow the correct specifications described in the Point documentation.static PolygonfromLngLats(List<List<Point>> coordinates, 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 PolygonfromOuterInner(LineString outer, BoundingBox bbox, LineString... inner) Create a new instance of this class by passing in an outerLineStringand optionally one or more inner LineStrings.static PolygonfromOuterInner(LineString outer, BoundingBox bbox, List<LineString> inner) Create a new instance of this class by passing in an outerLineStringand optionally one or more inner LineStrings contained within a list.static PolygonfromOuterInner(LineString outer, LineString... inner) Create a new instance of this class by passing in an outerLineStringand optionally one or more inner LineStrings.static PolygonfromOuterInner(LineString outer, List<LineString> inner) Create a new instance of this class by passing in an outerLineStringand optionally one or more inner LineStrings contained within a list.inthashCode()inner()Convenience method to get a list of innerLineStrings defining holes inside the polygon.outer()Convenience method to get the outerLineStringwhich defines the outer perimeter of the polygon.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 returnPolygon.static com.google.gson.TypeAdapter<Polygon>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 Polygon object from scratch it is better to use one of the other provided static factory methods such asfromOuterInner(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.- Parameters:
json- a formatted valid JSON string defining a GeoJson Polygon- Returns:
- a new instance of this class defined by the values passed inside this static factory method
- Since:
- 1.0.0
-
fromLngLats
Create a new instance of this class by defining a list ofPoints 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.- Parameters:
coordinates- a list of a list of points which represent the polygon 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 Polygon fromLngLats(@NonNull List<List<Point>> coordinates, @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 the first and last point in the list should be the same enclosing the linear ring.- Parameters:
coordinates- a list of a list of points which represent the polygon 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
-
fromOuterInner
Create a new instance of this class by passing in an outerLineStringand 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
RuntimeExceptionwill be thrown.- Parameters:
outer- a LineString which defines the outer perimeter of the polygoninner- one or more LineStrings representing holes inside the outer perimeter- Returns:
- a new instance of this class defined by the values passed inside this static factory method
- Since:
- 3.0.0
-
fromOuterInner
public static Polygon fromOuterInner(@NonNull LineString outer, @Nullable BoundingBox bbox, @Nullable LineString... inner) Create a new instance of this class by passing in an outerLineStringand 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
RuntimeExceptionwill be thrown.- Parameters:
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 perimeter- Returns:
- a new instance of this class defined by the values passed inside this static factory method
- Since:
- 3.0.0
-
fromOuterInner
Create a new instance of this class by passing in an outerLineStringand 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
RuntimeExceptionwill be thrown.- Parameters:
outer- a LineString which defines the outer perimeter of the polygoninner- one or more LineStrings inside a list representing holes inside the outer perimeter- Returns:
- a new instance of this class defined by the values passed inside this static factory method
- Since:
- 3.0.0
-
fromOuterInner
public static Polygon fromOuterInner(@NonNull LineString outer, @Nullable BoundingBox bbox, @Nullable List<LineString> inner) Create a new instance of this class by passing in an outerLineStringand 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
RuntimeExceptionwill be thrown.- Parameters:
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- Returns:
- a new instance of this class defined by the values passed inside this static factory method
- Since:
- 3.0.0
-
outer
Convenience method to get the outerLineStringwhich defines the outer perimeter of the polygon.- Returns:
- a
LineStringdefining the outer perimeter of this polygon - Since:
- 3.0.0
-
inner
Convenience method to get a list of innerLineStrings 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.- Returns:
- a List of
LineStrings defining holes inside the polygon - Since:
- 3.0.0
-
type
This describes the TYPE of GeoJson geometry this object is, thus this will always returnPolygon. -
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
Provides the list ofPoints 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).- Specified by:
coordinatesin interfaceCoordinateContainer<List<List<Point>>>- Returns:
- a list of points
- 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()
-