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
| Attribute | Type | Description |
|---|---|---|
| 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. |
| coords | tuple | A 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
| Name | Type | Description |
|---|---|---|
| *args | Any | Variable length argument list where the first argument is the exterior ring and subsequent arguments (or a single sequence) are the interior rings. |
| **kwargs | Any | Keyword 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
| Name | Type | Description |
|---|---|---|
| bbox | tuple | A 4-tuple of (xmin, ymin, xmax, ymax) defining the polygon boundaries. |
Returns
| Type | Description |
|---|---|
[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
| Type | Description |
|---|---|
int | The count of holes (interior boundaries) within the polygon. |
tuple()
@classmethod
def tuple() - > tuple
Get the tuple for each ring in this Polygon.
Returns
| Type | Description |
|---|---|
tuple | A 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
| Type | Description |
|---|---|
str | A string containing the XML-formatted KML < Polygon > element. |