Class: QgsGeometryCollection

class qgis.core.QgsGeometryCollection

Bases: QgsAbstractGeometry

Geometry collection

QgsGeometryCollection() Constructor for an empty geometry collection.

QgsGeometryCollection(c: QgsGeometryCollection)

Methods

addGeometry

Adds a geometry and takes ownership.

addMValue

param mValue:

addZValue

param zValue:

adjacentVertices

param vertex:

area

rtype:

float

asGml2

param doc:

asGml3

param doc:

asKml

param precision:

asQPainterPath

rtype:

QPainterPath

asWkb

param flags:

asWkt

param precision:

boundary

rtype:

QgsAbstractGeometry

boundingBox3D

rtype:

QgsBox3D

boundingBoxIntersects

param box3d:

calculateBoundingBox

Default calculator for the minimal bounding box for the geometry.

calculateBoundingBox3D

rtype:

QgsBox3D

childCount

rtype:

int

childGeometry

param index:

childPoint

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

clear

clearCache

clone

rtype:

QgsGeometryCollection

closestSegment

param pt:

compareToSameClass

param other:

coordinateSequence

rtype:

object

createEmptyWithSameType

rtype:

QgsGeometryCollection

deleteVertex

param position:

dimension

rtype:

int

draw

param p:

dropMValue

rtype:

bool

dropZValue

rtype:

bool

extractPartsByType

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

fromCollectionWkt

Reads a collection from a WKT string.

fromWkb

param wkb:

fromWkt

param wkt:

fuzzyDistanceEqual

param other:

fuzzyEqual

param other:

geometryN

Returns a geometry from within the collection.

geometryType

rtype:

str

hasChildGeometries

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

hasCurvedSegments

rtype:

bool

insertGeometry

Inserts a geometry before a specified index and takes ownership.

insertVertex

param position:

isEmpty

rtype:

bool

isValid

param flags:

length

rtype:

float

moveVertex

param position:

nCoordinates

rtype:

int

nextVertex

param id:

normalize

numGeometries

Returns the number of geometries within the collection.

partCount

rtype:

int

perimeter

rtype:

float

removeDuplicateNodes

param epsilon:

removeGeometry

Removes a geometry from the collection by index.

reserve

Attempts to allocate memory for at least size geometries.

ringCount

param part:

segmentLength

param startVertex:

segmentize

Returns a geometry without curves.

setZMTypeFromSubGeometry

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

simplifiedTypeRef

rtype:

QgsAbstractGeometry

snappedToGrid

param hSpacing:

sortIndex

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

swapXy

toCurveType

rtype:

QgsGeometryCollection

transform

param ct:

vertexAngle

param vertex:

vertexAt

param id:

vertexCount

param part:

vertexNumberFromVertexId

param id:

wkbSize

param flags:

wktOmitChildType

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

addGeometry(self, g: QgsAbstractGeometry) bool

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

Parameters:

g (QgsAbstractGeometry)

Return type:

bool

addMValue(self, mValue: float = 0) bool
Parameters:

mValue (float = 0)

Return type:

bool

addZValue(self, zValue: float = 0) bool
Parameters:

zValue (float = 0)

Return type:

bool

adjacentVertices(self, vertex: QgsVertexId) Tuple[QgsVertexId, QgsVertexId]
Parameters:

vertex (QgsVertexId)

Return type:

Tuple[QgsVertexId, QgsVertexId]

area(self) float
Return type:

float

asGml2(self, doc: QDomDocument, precision: int = 17, ns: str = '', axisOrder: QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) QDomElement
Parameters:
  • doc (QDomDocument)

  • precision (int = 17)

  • ns (str = '')

  • axisOrder (QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY)

Return type:

QDomElement

asGml3(self, doc: QDomDocument, precision: int = 17, ns: str = '', axisOrder: QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) QDomElement
Parameters:
  • doc (QDomDocument)

  • precision (int = 17)

  • ns (str = '')

  • axisOrder (QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY)

Return type:

QDomElement

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

precision (int = 17)

Return type:

str

asQPainterPath(self) QPainterPath
Return type:

QPainterPath

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

boundingBox3D(self) QgsBox3D
Return type:

QgsBox3D

boundingBoxIntersects(self, box3d: QgsBox3D) bool
Parameters:

box3d (QgsBox3D)

Return type:

bool

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
Return type:

QgsBox3D

childCount(self) int
Return type:

int

childGeometry(self, index: int) QgsAbstractGeometry
Parameters:

index (int)

Return type:

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) QgsGeometryCollection
Return type:

QgsGeometryCollection

closestSegment(self, pt: QgsPoint, epsilon: float = 4 * DBL_EPSILON) Tuple[float, QgsPoint, QgsVertexId, int]
Parameters:
  • pt (QgsPoint)

  • epsilon (float = 4*DBL_EPSILON)

Return type:

Tuple[float, QgsPoint, QgsVertexId, int]

compareToSameClass(self, other: QgsAbstractGeometry) int
Parameters:

other (QgsAbstractGeometry)

Return type:

int

coordinateSequence(self) object
Return type:

object

createEmptyWithSameType(self) QgsGeometryCollection
Return type:

QgsGeometryCollection

deleteVertex(self, position: QgsVertexId) bool
Parameters:

position (QgsVertexId)

Return type:

bool

dimension(self) int
Return type:

int

draw(self, p: QPainter)
Parameters:

p (QPainter)

dropMValue(self) bool
Return type:

bool

dropZValue(self) bool
Return type:

bool

extractPartsByType(self, type: Qgis.WkbType, useFlatType: bool = True) QgsGeometryCollection

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:

QgsGeometryCollection

fromCollectionWkt(self, wkt: str, subtypes: Iterable[QgsAbstractGeometry], defaultChildWkbType: str = '') bool

Reads a collection from a WKT string.

Parameters:
Return type:

bool

fromWkb(self, wkb: QgsConstWkbPtr) bool
Parameters:

wkb (QgsConstWkbPtr)

Return type:

bool

fromWkt(self, wkt: str) bool
Parameters:

wkt (str)

Return type:

bool

fuzzyDistanceEqual(self, other: QgsAbstractGeometry, epsilon: float = 1e-08) bool
Parameters:
Return type:

bool

fuzzyEqual(self, other: QgsAbstractGeometry, epsilon: float = 1e-08) bool
Parameters:
Return type:

bool

geometryN(self, n: int) QgsAbstractGeometry

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

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

hasCurvedSegments(self) bool
Return type:

bool

insertGeometry(self, g: QgsAbstractGeometry, index: int) bool

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

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

  • index (int) – position to insert geometry before

Return type:

bool

insertVertex(self, position: QgsVertexId, vertex: QgsPoint) bool
Parameters:
Return type:

bool

isEmpty(self) bool
Return type:

bool

isValid(self, flags: Qgis.GeometryValidityFlags | Qgis.GeometryValidityFlag = Qgis.GeometryValidityFlags()) Tuple[bool, str]
Parameters:

flags (Union[Qgis.GeometryValidityFlags)

Return type:

Tuple[bool, str]

length(self) float
Return type:

float

moveVertex(self, position: QgsVertexId, newPos: QgsPoint) bool
Parameters:
Return type:

bool

nCoordinates(self) int
Return type:

int

nextVertex(self, id: QgsVertexId) Tuple[bool, QgsPoint]
Parameters:

id (QgsVertexId)

Return type:

Tuple[bool, QgsPoint]

normalize(self)
numGeometries(self) int

Returns the number of geometries within the collection.

Return type:

int

partCount(self) int
Return type:

int

perimeter(self) float
Return type:

float

removeDuplicateNodes(self, epsilon: float = 4 * DBL_EPSILON, useZValues: bool = False) bool
Parameters:
  • epsilon (float = 4*DBL_EPSILON)

  • useZValues (bool = False)

Return type:

bool

removeGeometry(self, nr: int) bool

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)

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)

ringCount(self, part: int = 0) int
Parameters:

part (int = 0)

Return type:

int

segmentLength(self, startVertex: QgsVertexId) float
Parameters:

startVertex (QgsVertexId)

Return type:

float

segmentize(self, tolerance: float = M_PI_2 / 90, toleranceType: QgsAbstractGeometry.SegmentationToleranceType = QgsAbstractGeometry.MaximumAngle) QgsAbstractGeometry

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:

QgsAbstractGeometry

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

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

simplifiedTypeRef(self) QgsAbstractGeometry
Return type:

QgsAbstractGeometry

snappedToGrid(self, hSpacing: float, vSpacing: float, dSpacing: float = 0, mSpacing: float = 0) QgsGeometryCollection
Parameters:
  • hSpacing (float)

  • vSpacing (float)

  • dSpacing (float = 0)

  • mSpacing (float = 0)

Return type:

QgsGeometryCollection

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.

swapXy(self)
toCurveType(self) QgsGeometryCollection
Return type:

QgsGeometryCollection

transform(self, ct: QgsCoordinateTransform, d: Qgis.TransformDirection = Qgis.TransformDirection.Forward, transformZ: bool = False)
transform(self, t: QTransform, zTranslate: float = 0, zScale: float = 1, mTranslate: float = 0, mScale: float = 1) None
transform(self, transformer: QgsAbstractGeometryTransformer, feedback: QgsFeedback = None) bool
Parameters:
  • ct (QgsCoordinateTransform)

  • d (Qgis.TransformDirection = Qgis.TransformDirection.Forward)

  • transformZ (bool = False)

vertexAngle(self, vertex: QgsVertexId) float
Parameters:

vertex (QgsVertexId)

Return type:

float

vertexAt(self, id: QgsVertexId) QgsPoint
Parameters:

id (QgsVertexId)

Return type:

QgsPoint

vertexCount(self, part: int = 0, ring: int = 0) int
Parameters:
  • part (int = 0)

  • ring (int = 0)

Return type:

int

vertexNumberFromVertexId(self, id: QgsVertexId) int
Parameters:

id (QgsVertexId)

Return type:

int

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

flags (Union[QgsAbstractGeometry.WkbFlags)

Return type:

int

wktOmitChildType(self) bool

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

Return type:

bool