Class: QgsGeometryCollection

Geometry collection.

Class Hierarchy

Inheritance diagram of qgis.core.QgsGeometryCollection

Base classes

QgsAbstractGeometry

Abstract base class for all geometries.

Subclasses

QgsMultiCurve

Multi curve geometry collection.

QgsMultiPoint

Multi point geometry collection.

QgsMultiSurface

Multi surface geometry collection.

Methods

extractPartsByType

Returns a new QgsGeometryCollection subclass which consists of the parts of this collection which match the specified WKB type.

geometryN

Returns a geometry from within the collection.

numGeometries

Returns the number of geometries within the collection.

reserve

Attempts to allocate memory for at least size geometries.

takeGeometries

Removes all geometries from the collection, returning them and their ownership to the caller.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsGeometryCollection. See the FAQ for more details.

addGeometries

Adds a list of geometries to the collection, transferring ownership to the collection.

addGeometry

Adds a geometry and takes ownership.

insertGeometry

Inserts a geometry before a specified index and takes ownership.

removeGeometry

Removes a geometry from the collection by index.

segmentize

Returns a geometry without curves.

wktOmitChildType

Returns whether child type names are omitted from Wkt representations of the collection

class qgis.core.QgsGeometryCollection[source]

Bases: QgsAbstractGeometry

__init__()

Constructor for an empty geometry collection.

__init__(c: QgsGeometryCollection)
Parameters:

c (QgsGeometryCollection)

virtual addGeometries(self, geometries: Iterable[QgsAbstractGeometry]) bool[source]

Adds a list of geometries to the collection, transferring ownership to the collection.

Returns True in case of success.

Added in version 3.38.

Parameters:

geometries (Iterable[QgsAbstractGeometry])

Return type:

bool

virtual addGeometry(self, g: QgsAbstractGeometry | None) bool[source]

Adds a geometry and takes ownership. Returns True in case of success.

Parameters:

g (Optional[QgsAbstractGeometry])

Return type:

bool

extractPartsByType(self, type: Qgis.WkbType, useFlatType: bool = True) QgsGeometryCollection | None[source]

Returns a new QgsGeometryCollection subclass which consists of the parts of this collection which match the specified WKB type.

For instance, if type is Qgis.WkbType.Polygon, then the returned object will be a QgsMultiPolygon object containing just the polygons from this collection.

If useFlatType is True, then the WKB types of component geometries from this collection will be flattened prior to comparing with type. (I.e. the presence of Z / M dimensions will be ignored when comparing against type).

Added in version 3.36.

Parameters:
Return type:

Optional[QgsGeometryCollection]

geometryN(self, n: int) QgsAbstractGeometry[source]

Returns a geometry from within the collection.

Parameters:

n (int) – index of geometry to return.

Raises:

IndexError – if no geometry with the specified index exists.

Return type:

QgsAbstractGeometry

virtual insertGeometry(self, g: QgsAbstractGeometry | None, index: int) bool[source]

Inserts a geometry before a specified index and takes ownership. Returns True in case of success.

Parameters:
  • g (Optional[QgsAbstractGeometry]) – geometry to insert. Ownership is transferred to the collection.

  • index (int) – position to insert geometry before

Return type:

bool

numGeometries(self) int[source]

Returns the number of geometries within the collection.

Return type:

int

virtual removeGeometry(self, nr: int) bool[source]

Removes a geometry from the collection by index.

Return type:

bool

Returns:

True if removal was successful.

Raises:

IndexError – if no geometry with the specified index exists.

Parameters:

nr (int)

reserve(self, size: int)[source]

Attempts to allocate memory for at least size geometries.

If the number of geometries is known in advance, calling this function prior to adding geometries will prevent reallocations and memory fragmentation.

Added in version 3.10.

Parameters:

size (int)

virtual segmentize(self, tolerance: float = M_PI_2 / 90, toleranceType: QgsAbstractGeometry.SegmentationToleranceType = QgsAbstractGeometry.MaximumAngle) QgsAbstractGeometry | None[source]

Returns a geometry without curves. Caller takes ownership

Parameters:
  • tolerance (float = M_PI_2/90) – segmentation tolerance

  • toleranceType (QgsAbstractGeometry.SegmentationToleranceType = QgsAbstractGeometry.MaximumAngle) – maximum segmentation angle or maximum difference between approximation and curve

Return type:

Optional[QgsAbstractGeometry]

takeGeometries(self) List[QgsAbstractGeometry]

Removes all geometries from the collection, returning them and their ownership to the caller.

Added in version 3.38.

Return type:

List[QgsAbstractGeometry]

virtual wktOmitChildType(self) bool[source]

Returns whether child type names are omitted from Wkt representations of the collection

Return type:

bool