Skip to main content

Polygon

This class represents a GEOS polygon geometry composed of an exterior ring and an optional sequence of interior rings (holes). It provides functionality for initializing polygons from linear rings, coordinate sequences, or bounding boxes, and supports list-like iteration over its constituent rings. The class also includes properties for accessing the exterior shell and generating KML representations.

Attributes

AttributeTypeDescription
exterior_ring[LinearRing](../linestring/linearring.md?sid=django_contrib_gis_geos_linestring_linearring)The exterior ring of the Polygon, which can be accessed or updated as a LinearRing object.
shell[LinearRing](../linestring/linearring.md?sid=django_contrib_gis_geos_linestring_linearring)An alias for the exterior_ring property providing access to the polygon's outer boundary.
coordstupleA tuple containing the coordinate sequences for each ring in the polygon, starting with the exterior ring.

Constructor

Signature

def Polygon(
*args: Any,
**kwargs: Any
) - > null

Parameters

NameTypeDescription
*argsAnyVariable length argument list where the first argument is the exterior ring and subsequent arguments (or a single sequence) are the interior rings.
**kwargsAnyKeyword arguments passed to the GEOSGeometry parent class constructor, such as 'srid'.

Methods


from_bbox()

@classmethod
def from_bbox(
bbox: tuple
) - > [Polygon](polygon.md?sid=django_contrib_gis_geos_polygon_polygon)

Construct a Polygon from a bounding box (4-tuple).

Parameters

NameTypeDescription
bboxtupleA 4-tuple of (xmin, ymin, xmax, ymax) defining the polygon boundaries.

Returns

TypeDescription
[Polygon](polygon.md?sid=django_contrib_gis_geos_polygon_polygon)A new Polygon instance representing the rectangular area defined by the bounding box.

num_interior_rings()

@classmethod
def num_interior_rings() - > int

Return the number of interior rings.

Returns

TypeDescription
intThe count of holes (interior boundaries) within the polygon.

tuple()

@classmethod
def tuple() - > tuple

Get the tuple for each ring in this Polygon.

Returns

TypeDescription
tupleA nested tuple containing the coordinate tuples for the exterior ring and all interior rings.

kml()

@classmethod
def kml() - > str

Return the KML representation of this Polygon.

Returns

TypeDescription
strA string containing the XML-formatted KML < Polygon > element.