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
Returns a new |
|
Returns a geometry from within the collection. |
|
Returns the number of geometries within the collection. |
|
Attempts to allocate memory for at least size geometries. |
|
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.
Adds a list of geometries to the collection, transferring ownership to the collection. |
|
Adds a geometry and takes ownership. |
|
Inserts a geometry before a specified index and takes ownership. |
|
Removes a geometry from the collection by index. |
|
Returns a geometry without curves. |
|
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:
- 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 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]
- 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:
- 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]