Class: QgsPolygon

class qgis.core.QgsPolygon

Bases: QgsCurvePolygon

Polygon geometry type.

QgsPolygon() Constructor for an empty polygon geometry.

QgsPolygon(exterior: QgsLineString, rings: Iterable[QgsLineString] = []) Constructor for QgsPolygon, with the specified exterior ring and interior rings.

Ownership of exterior and rings is transferred to the polygon.

Added in version 3.14.

QgsPolygon(QgsPolygon)

Methods

addInteriorRing

param ring:

asWkb

param flags:

asWkt

param precision:

boundary

rtype:

QgsAbstractGeometry

calculateBoundingBox

Default calculator for the minimal bounding box for the geometry.

calculateBoundingBox3D

childCount

childGeometry

childPoint

Returns point at index (for geometries without child geometries - i.e. curve / point).

clear

clearCache

clone

rtype:

QgsPolygon

compareToSameClass

createEmptyWithSameType

rtype:

QgsPolygon

fromWkb

param wkb:

geometryType

rtype:

str

hasChildGeometries

Returns whether the geometry has any child geometries (False for point / curve, True otherwise)

pointDistanceToBoundary

Returns the distance from a point to the boundary of the polygon (either the exterior ring or any closer interior rings).

setExteriorRing

param ring:

setZMTypeFromSubGeometry

Updates the geometry type based on whether sub geometries contain z or m values.

sortIndex

Returns the sort index for the geometry, used in the compareTo() method to compare geometries of different types.

surfaceToPolygon

rtype:

QgsPolygon

toCurveType

Returns the geometry converted to the more generic curve type QgsCurvePolygon

wkbSize

param flags:

addInteriorRing(self, ring: QgsCurve)
Parameters:

ring (QgsCurve)

asWkb(self, flags: QgsAbstractGeometry.WkbFlags | QgsAbstractGeometry.WkbFlag = QgsAbstractGeometry.WkbFlags()) QByteArray
Parameters:

flags (Union[QgsAbstractGeometry.WkbFlags)

Return type:

QByteArray

asWkt(self, precision: int = 17) str
Parameters:

precision (int = 17)

Return type:

str

boundary(self) QgsAbstractGeometry
Return type:

QgsAbstractGeometry

calculateBoundingBox(self) QgsRectangle

Default calculator for the minimal bounding box for the geometry. Derived classes should override this method if a more efficient bounding box calculation is available.

calculateBoundingBox3D(self) QgsBox3D
childCount(self) int
childGeometry(self, index: int) QgsAbstractGeometry
childPoint(self, index: int) QgsPoint

Returns point at index (for geometries without child geometries - i.e. curve / point)

Note

used for vertex_iterator implementation

clear(self)
clearCache(self)
clone(self) QgsPolygon
Return type:

QgsPolygon

compareToSameClass(self, other: QgsAbstractGeometry) int
createEmptyWithSameType(self) QgsPolygon
Return type:

QgsPolygon

fromWkb(self, wkb: QgsConstWkbPtr) bool
Parameters:

wkb (QgsConstWkbPtr)

Return type:

bool

geometryType(self) str
Return type:

str

hasChildGeometries(self) bool

Returns whether the geometry has any child geometries (False for point / curve, True otherwise)

Note

used for vertex_iterator implementation

pointDistanceToBoundary(self, x: float, y: float) float

Returns the distance from a point to the boundary of the polygon (either the exterior ring or any closer interior rings). The returned distance will be negative if the point lies outside the polygon.

Parameters:
  • x (float)

  • y (float)

Return type:

float

setExteriorRing(self, ring: QgsCurve)
Parameters:

ring (QgsCurve)

setZMTypeFromSubGeometry(self, subggeom: QgsAbstractGeometry, baseGeomType: Qgis.WkbType)

Updates the geometry type based on whether sub geometries contain z or m values.

sortIndex(self) int

Returns the sort index for the geometry, used in the compareTo() method to compare geometries of different types.

Added in version 3.20.

surfaceToPolygon(self) QgsPolygon
Return type:

QgsPolygon

toCurveType(self) QgsCurvePolygon

Returns the geometry converted to the more generic curve type QgsCurvePolygon

Return type:

QgsCurvePolygon

Returns:

the converted geometry. Caller takes ownership

wkbSize(self, flags: QgsAbstractGeometry.WkbFlags | QgsAbstractGeometry.WkbFlag = QgsAbstractGeometry.WkbFlags()) int
Parameters:

flags (Union[QgsAbstractGeometry.WkbFlags)

Return type:

int