Class: QgsGeometryCollection

class qgis.core.QgsGeometryCollection

Bases: QgsAbstractGeometry

Geometry collection

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

asWkb

rtype

QByteArray

asWkt

param precision

boundary

rtype

QgsAbstractGeometry

boundingBox

rtype

QgsRectangle

calculateBoundingBox

rtype

QgsRectangle

childCount

rtype

int

childGeometry

param index

childPoint

clear

clearCache

clone

rtype

QgsGeometryCollection

closestSegment

param pt

coordinateSequence

rtype

object

createEmptyWithSameType

rtype

QgsGeometryCollection

deleteVertex

param position

dimension

rtype

int

draw

param p

dropMValue

rtype

bool

dropZValue

rtype

bool

fromCollectionWkt

Reads a collection from a WKT string.

fromWkb

param wkb

fromWkt

param wkt

geometryN

Returns a geometry from within the collection.

geometryType

rtype

str

hasChildGeometries

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

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

snappedToGrid

param hSpacing

swapXy

toCurveType

rtype

QgsGeometryCollection

transform

transform(self, t: QTransform, zTranslate: float = 0, zScale: float = 1, mTranslate: float = 0, mScale: float = 1)

vertexAngle

param vertex

vertexAt

param id

vertexCount

param part

vertexNumberFromVertexId

param id

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

asWkb(self) → QByteArray
Return type

QByteArray

asWkt(self, precision: int = 17) → str
Parameters

precision (int = 17) –

Return type

str

boundary(self) → QgsAbstractGeometry
Return type

QgsAbstractGeometry

boundingBox(self) → QgsRectangle
Return type

QgsRectangle

calculateBoundingBox(self) → QgsRectangle
Return type

QgsRectangle

childCount(self) → int
Return type

int

childGeometry(self, index: int) → QgsAbstractGeometry
Parameters

index (int) –

Return type

QgsAbstractGeometry

childPoint()
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]

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

fromCollectionWkt(self, wkt: str, subtypes: object, defaultChildWkbType: str = '') → bool

Reads a collection from a WKT string.

Parameters
  • wkt (str) –

  • subtypes (object) –

  • defaultChildWkbType (str = '') –

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

geometryN(self, n: int) → QgsAbstractGeometry

Returns a geometry from within the collection.

Parameters

n (int) – index of geometry to return. An IndexError will be raised if no geometry with the specified index exists.

Return type

QgsAbstractGeometry

geometryType(self) → str
Return type

str

hasChildGeometries()
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: int = 0) → Tuple[bool, str]
Parameters

flags (int = 0) –

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]

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.

An IndexError will be raised if no geometry with the specified index exists.

Return type

bool

Returns

True if removal was successful.

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.

New 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()
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

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

QgsGeometryCollection

transform(self, ct: QgsCoordinateTransform, d: QgsCoordinateTransform.TransformDirection = QgsCoordinateTransform.ForwardTransform, transformZ: bool = False)

transform(self, t: QTransform, zTranslate: float = 0, zScale: float = 1, mTranslate: float = 0, mScale: float = 1)

Parameters
  • ct (QgsCoordinateTransform) –

  • d (QgsCoordinateTransform.TransformDirection = QgsCoordinateTransform.ForwardTransform) –

  • 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

wktOmitChildType(self) → bool

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

New in version 2.12.

Return type

bool