Polygon¶
@Serializable(with = Geo.Polygon.Serializer::class)
data class Polygon(val rings: List<Geo.LineString>) : Geo
A GeoJSON polygon.
A polygon is a shape that may have holes.
A simple polygon has a single ring (e.g., a triangle, a square). More complex polygons can have multiple rings that represent holes (e.g., a doughnut shape).
To learn more about the different kinds of polygons, see the constructors.
External resources¶
Constructors¶
Polygon¶
constructor(rings: List<Geo.LineString>)
constructor(vararg rings: Geo.LineString)
Constructs a Polygon instance from multiple LineString instances.
Each LineString instance represents a ring.
-
Each ring must have at least 4 points, be
closed, and must not self-intersect. -
The first described ring must be the exterior ring.
-
The exterior ring cannot self-intersect.
-
Any interior ring must be entirely contained by the outer ring.
-
Interior rings cannot intersect or overlap each other. Interior rings cannot share an edge.
Interior rings represent holes in the external ring.
Example
A square within another square. Note that the exterior square is described first.
Geo.Polygon(
Geo.LineString(
Geo.Point(Geo.Longitude(0.0), Geo.Latitude(0.0)),
Geo.Point(Geo.Longitude(10.0), Geo.Latitude(0.0)),
Geo.Point(Geo.Longitude(10.0), Geo.Latitude(10.0)),
Geo.Point(Geo.Longitude(0.0), Geo.Latitude(10.0)),
Geo.Point(Geo.Longitude(0.0), Geo.Latitude(0.0)),
),
Geo.LineString(
Geo.Point(Geo.Longitude(2.0), Geo.Latitude(2.0)),
Geo.Point(Geo.Longitude(8.0), Geo.Latitude(2.0)),
Geo.Point(Geo.Longitude(8.0), Geo.Latitude(8.0)),
Geo.Point(Geo.Longitude(2.0), Geo.Latitude(8.0)),
Geo.Point(Geo.Longitude(2.0), Geo.Latitude(2.0)),
),
)
External resources
constructor(vararg points: Geo.Point)
Constructs a single-ring Geo.Polygon instance from multiple Point instances.
The polygon must have at least 4 points, be closed, and must not self-intersect.
Example
A square:
Geo.Polygon(
Geo.Point(Geo.Longitude(0.0), Geo.Latitude(0.0)),
Geo.Point(Geo.Longitude(1.0), Geo.Latitude(0.0)),
Geo.Point(Geo.Longitude(1.0), Geo.Latitude(1.0)),
Geo.Point(Geo.Longitude(0.0), Geo.Latitude(1.0)),
Geo.Point(Geo.Longitude(0.0), Geo.Latitude(0.0)),
)
External resources
Types¶
Serializer¶
@LowLevelApi
object Serializer : KSerializer<Geo.Polygon>
Properties¶
rings¶
val rings: List<Geo.LineString>
The various rings of this polygon.
A polygon must have at least one ring.
Each ring must have at least 4 points, be closed, and must not self-intersect. For the complete rules on rings, see the constructor that takes a vararg of LineString.