Class: QgsGeometryCollection¶
Geometry collection
Class Hierarchy¶
Base classes¶
Abstract base class for all geometries |
Subclasses¶
Multi curve geometry collection. |
|
Multi point geometry collection. |
|
Multi surface geometry collection. |
Methods
Adds a list of geometries to the collection, transferring ownership to the collection. |
|
Adds a geometry and takes ownership. |
|
Returns a new |
|
Reads a collection from a WKT string. |
|
Returns a geometry from within the collection. |
|
Inserts a geometry before a specified index and takes ownership. |
|
Returns the number of geometries within the collection. |
|
Removes a geometry from the collection by index. |
|
Attempts to allocate memory for at least size geometries. |
|
Returns a geometry without curves. |
|
Removes all geometries from the collection, returning them and their ownership to the caller. |
|
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:
- 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
- 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 WKBtype
.For instance, if
type
isQgis
.WkbType.Polygon, then the returned object will be aQgsMultiPolygon
object containing just the polygons from this collection.If
useFlatType
isTrue
, then the WKB types of component geometries from this collection will be flattened prior to comparing withtype
. (I.e. the presence of Z / M dimensions will be ignored when comparing againsttype
).Added in version 3.36.
- Parameters:
type (Qgis.WkbType)
useFlatType (bool = True)
- Return type:
Optional[QgsGeometryCollection]
- fromCollectionWkt(self, wkt: str | None, subtypes: Iterable[QgsAbstractGeometry], defaultChildWkbType: str | None = '') bool [source]¶
Reads a collection from a WKT string.
- Parameters:
wkt (Optional[str])
subtypes (Iterable[QgsAbstractGeometry])
defaultChildWkbType (Optional[str] = '')
- Return type:
bool
- 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:
- 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
- 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)
- 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]