Class: QgsPolygon¶
- class qgis.core.QgsPolygon¶
Bases:
QgsCurvePolygon
Polygon geometry type.
Added in version 2.10.
QgsPolygon() Constructor for an empty polygon geometry.
QgsPolygon(exterior: Optional[QgsLineString], rings: Iterable[QgsLineString] = []) Constructor for
QgsPolygon
, with the specifiedexterior
ring and interiorrings
.Ownership of
exterior
andrings
is transferred to the polygon.Added in version 3.14.
QgsPolygon(a0:
QgsPolygon
)Methods
- param ring:
- param flags:
- rtype:
Optional[QgsAbstractGeometry]
Default calculator for the minimal bounding box for the geometry.
Returns point at index (for geometries without child geometries - i.e. curve / point).
- rtype:
Optional[QgsPolygon]
- rtype:
Optional[QgsPolygon]
- param wkb:
- rtype:
str
Returns whether the geometry has any child geometries (
False
for point / curve,True
otherwise)Returns the distance from a point to the boundary of the polygon (either the exterior ring or any closer interior rings).
- param ring:
Updates the geometry type based on whether sub geometries contain z or m values.
Returns the sort index for the geometry, used in the
compareTo()
method to compare geometries of different types.- rtype:
Optional[QgsPolygon]
Returns the geometry converted to the more generic curve type
QgsCurvePolygon
- param flags:
- asWkb(self, flags: QgsAbstractGeometry.WkbFlags | QgsAbstractGeometry.WkbFlag = QgsAbstractGeometry.WkbFlags()) QByteArray ¶
- Parameters:
flags (Union[QgsAbstractGeometry.WkbFlags)
- Return type:
QByteArray
- boundary(self) QgsAbstractGeometry | None ¶
- Return type:
Optional[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.
- childCount(self) int ¶
- childGeometry(self, index: int) QgsAbstractGeometry | None ¶
- childPoint(self, index: int) QgsPoint ¶
Returns point at index (for geometries without child geometries - i.e. curve / point)
Note
used for vertex_iterator implementation
Added in version 3.0.
- clear(self)¶
- clearCache(self)¶
- clone(self) QgsPolygon | None ¶
- Return type:
Optional[QgsPolygon]
- compareToSameClass(self, other: QgsAbstractGeometry | None) int ¶
- createEmptyWithSameType(self) QgsPolygon | None ¶
- Return type:
Optional[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
Added in version 3.0.
- 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.
Added in version 3.0.
- Parameters:
x (float)
y (float)
- Return type:
float
- setZMTypeFromSubGeometry(self, subggeom: QgsAbstractGeometry | None, 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 | None ¶
- Return type:
Optional[QgsPolygon]
- toCurveType(self) QgsCurvePolygon | None ¶
Returns the geometry converted to the more generic curve type
QgsCurvePolygon
- Return type:
Optional[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