Class: QgsTopologicalMesh

Wraps a QgsMesh to ensure the consistency of the mesh during editing and helps to access elements from other elements.

A topological face must:

  • be convex

  • be oriented counter-clockwise

  • not share a unique vertex with another face

Added in version 3.22.

class qgis.core.QgsTopologicalMesh[source]

Bases: object

class Changes[source]

Bases: object

Contains topological differences between two states of a topological mesh, only accessible from the QgsTopologicalMesh class.

Added in version 3.22.

addedVertices(self) List[QgsPoint]

Returns the added vertices with this changes

Return type:

List[QgsPoint]

changedCoordinatesVerticesIndexes(self) List[int]

Returns the indexes of vertices that have changed coordinates

Return type:

List[int]

clearChanges(self)[source]

Clears all changes

isEmpty(self) bool[source]

Returns whether changes are empty, that there is nothing to change

Return type:

bool

nativeFacesIndexesGeometryChanged(self) List[int]

Returns a list of the native face indexes that have a geometry changed

Return type:

List[int]

newVerticesXYValues(self) List[QgsPointXY]

Returns the new (X,Y) values of vertices that have changed their coordinates

Return type:

List[QgsPointXY]

newVerticesZValues(self) List[float]

Returns the new Z values of vertices that have changed their coordinates

Return type:

List[float]

oldVerticesXYValues(self) List[QgsPointXY]

Returns the old (X,Y) values of vertices that have changed their coordinates

Return type:

List[QgsPointXY]

removedFaceIndexes(self) List[int]

Returns the indexes of the faces that are removed with this changes

Return type:

List[int]

verticesToRemoveIndexes(self) List[int]

Returns the indexes of vertices to remove

Return type:

List[int]

class TopologicalFaces[source]

Bases: object

Contains independent faces and topological information about these faces.

This class supports unique shared vertices between faces.

Added in version 3.22.

clear(self)[source]

Clears all data contained in the instance.

vertexToFace(self, vertexIndex: int) int[source]

Returns a face linked to the vertices with index vertexIndex

Parameters:

vertexIndex (int)

Return type:

int

addFaces(self, topologicFaces: QgsTopologicalMesh.TopologicalFaces) QgsTopologicalMesh.Changes[source]

Adds faces topologicFaces to the topologic mesh. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

topologicFaces (QgsTopologicalMesh.TopologicalFaces)

Return type:

QgsTopologicalMesh.Changes

addFreeVertex(self, vertex: QgsPoint) QgsTopologicalMesh.Changes[source]

Adds a free vertex in the face, that is a vertex that is not included or linked with any faces. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

vertex (QgsPoint)

Return type:

QgsTopologicalMesh.Changes

addVertexInFace(self, faceIndex: int, vertex: QgsPoint) QgsTopologicalMesh.Changes[source]

Adds a vertex in the face with index faceIndex. The including face is removed and new faces surrounding the added vertex are added. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:
Return type:

QgsTopologicalMesh.Changes

applyChanges(self, changes: QgsTopologicalMesh.Changes)[source]

Applies the changes

Parameters:

changes (QgsTopologicalMesh.Changes)

canBeMerged(self, vertexIndex1: int, vertexIndex2: int) bool[source]

Returns True if faces separated by vertices with indexes vertexIndex1 and vertexIndex2 can be merged

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

Return type:

bool

canBeSplit(self, faceIndex: int) bool[source]

Returns True if face with index faceIndex can be split

Parameters:

faceIndex (int)

Return type:

bool

changeXYValue(self, verticesIndexes: Iterable[int], newValues: Iterable[QgsPointXY]) QgsTopologicalMesh.Changes[source]

Changes the (X,Y) values of the vertices with indexes in vertices indexes with the values in newValues

Parameters:
  • verticesIndexes (Iterable[int])

  • newValues (Iterable[QgsPointXY])

Return type:

QgsTopologicalMesh.Changes

changeZValue(self, verticesIndexes: Iterable[int], newValues: Iterable[float]) QgsTopologicalMesh.Changes[source]

Changes the Z values of the vertices with indexes in vertices indexes with the values in newValues

Parameters:
  • verticesIndexes (Iterable[int])

  • newValues (Iterable[float])

Return type:

QgsTopologicalMesh.Changes

checkConsistency(self) QgsMeshEditingError[source]

Checks the consistency of the topological mesh and return False if there is a consistency issue

Return type:

QgsMeshEditingError

static checkTopology(mesh: QgsMesh, maxVerticesPerFace: int) QgsMeshEditingError[source]

Checks the topology of the mesh mesh, if error occurs, this mesh can’t be edited

Parameters:
  • mesh (QgsMesh)

  • maxVerticesPerFace (int)

Return type:

QgsMeshEditingError

static counterClockwiseFaces(face: Iterable[int], mesh: QgsMesh | None) QgsMeshEditingError[source]

Checks the topology of the face and sets it counter clockwise if necessary

Parameters:
  • face (Iterable[int])

  • mesh (Optional[QgsMesh])

Return type:

QgsMeshEditingError

static createTopologicalMesh(mesh: QgsMesh | None, maxVerticesPerFace: int, error: QgsMeshEditingError) QgsTopologicalMesh[source]

Creates a topologicaly consistent mesh with mesh, this static method modifies mesh to be topological consistent and return a QgsTopologicalMesh instance that contains and handles this mesh (does not take ownership).

Parameters:
Return type:

QgsTopologicalMesh

delaunayConditionForEdge(self, vertexIndex1: int, vertexIndex2: int) bool[source]

Check if Delaunay condition holds for given edge returns True if delaunay condition holds False otherwise

Added in version 3.42.

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

Return type:

bool

edgeCanBeFlipped(self, vertexIndex1: int, vertexIndex2: int) bool[source]

Returns True if the edge can be flipped (only available for edge shared by two faces with 3 vertices)

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

Return type:

bool

facesAroundVertex(self, vertexIndex: int) List[int]

Returns the indexes of faces that are around the vertex with index vertexIndex

Parameters:

vertexIndex (int)

Return type:

List[int]

facesCanBeAdded(self, topologicalFaces: QgsTopologicalMesh.TopologicalFaces) QgsMeshEditingError[source]

Returns whether the faces can be added to the mesh

Parameters:

topologicalFaces (QgsTopologicalMesh.TopologicalFaces)

Return type:

QgsMeshEditingError

facesCanBeRemoved(self, facesIndexes: Iterable[int]) QgsMeshEditingError[source]

Returns whether faces with index in faceIndexes can be removed The method an error object with type QgsMeshEditingError.NoError if the faces can be removed, otherwise returns the corresponding error

Parameters:

facesIndexes (Iterable[int])

Return type:

QgsMeshEditingError

firstFaceLinked(self, vertexIndex: int) int[source]

Returns the index of the first face linked, returns -1 if it is a free vertex or out of range index

Parameters:

vertexIndex (int)

Return type:

int

flipEdge(self, vertexIndex1: int, vertexIndex2: int) QgsTopologicalMesh.Changes[source]

Flips edge (vertexIndex1, vertexIndex2) The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

Return type:

QgsTopologicalMesh.Changes

freeVerticesIndexes(self) List[int]

Returns a list of vertices are not linked to any faces

Return type:

List[int]

insertVertexInFacesEdge(self, faceIndex: int, position: int, vertex: QgsPoint) QgsTopologicalMesh.Changes[source]

Inserts a vertex in the edge of face with index faceIndex at position . The faces that are on each side of the edge are removed and replaced by new faces constructed by a triangulation.

Parameters:
  • faceIndex (int)

  • position (int)

  • vertex (QgsPoint)

Return type:

QgsTopologicalMesh.Changes

isVertexFree(self, vertexIndex: int) bool[source]

Returns whether the vertex is a free vertex

Parameters:

vertexIndex (int)

Return type:

bool

isVertexOnBoundary(self, vertexIndex: int) bool[source]

Returns whether the vertex is on a boundary

Parameters:

vertexIndex (int)

Return type:

bool

merge(self, vertexIndex1: int, vertexIndex2: int) QgsTopologicalMesh.Changes[source]

Merges faces separated by vertices with indexes vertexIndex1 and vertexIndex2 The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

Return type:

QgsTopologicalMesh.Changes

mesh(self) QgsMesh | None[source]

Returns a pointer to the wrapped mesh

Return type:

Optional[QgsMesh]

neighborsOfFace(self, faceIndex: int) List[int]

Returns the indexes of neighbor faces of the face with index faceIndex

Parameters:

faceIndex (int)

Return type:

List[int]

reindex(self)[source]

Reindexes faces and vertices, after this operation, the topological mesh can’t be edited anymore and only the method mesh can be used to access to the raw mesh.

removeFaces(self, facesIndexes: Iterable[int]) QgsTopologicalMesh.Changes[source]

Removes faces with index in faceIndexes. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

facesIndexes (Iterable[int])

Return type:

QgsTopologicalMesh.Changes

removeVertexFillHole(self, vertexIndex: int) QgsTopologicalMesh.Changes[source]

Removes the vertex with index vertexIndex. If the vertex in linked with faces, the operation leads also to remove the faces. In this case, the hole is filled by a triangulation. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

vertexIndex (int)

Return type:

QgsTopologicalMesh.Changes

removeVertices(self, vertices: Iterable[int]) QgsTopologicalMesh.Changes[source]

Removes all the vertices with index in the list vertices If vertices in linked with faces, the operation leads also to remove the faces without filling holes. The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

vertices (Iterable[int])

Return type:

QgsTopologicalMesh.Changes

renumber(self) bool[source]

Renumbers the indexes of vertices and faces using the Reverse CutHill McKee Algorithm

Return type:

bool

reverseChanges(self, changes: QgsTopologicalMesh.Changes)[source]

Reverses the changes

Parameters:

changes (QgsTopologicalMesh.Changes)

splitFace(self, faceIndex: int) QgsTopologicalMesh.Changes[source]

Splits face with index faceIndex The method returns a instance of the class QgsTopologicalMesh.Change that can be used to reverse or reapply the operation.

Parameters:

faceIndex (int)

Return type:

QgsTopologicalMesh.Changes

static vertexPositionInFace(vertexIndex: int, face: Iterable[int]) int[source]

Returns vertex position in face

vertexPositionInFace(mesh: QgsMesh, vertexIndex: int, faceIndex: int) -> int Returns vertex position in face

Parameters:
  • vertexIndex (int)

  • face (Iterable[int])

Return type:

int