Class: QgsMeshEditor

Handles edit operations on a mesh layer.

Added in version 3.22.

Class Hierarchy

Inheritance diagram of qgis.core.QgsMeshEditor

Base classes

QObject

Methods

addFace

Adds a face face to the mesh with vertex indexes vertexIndexes, returns topological errors if this operation fails (operation is not realized)

addPointsAsVertices

Adds points as vertices in triangular mesh coordinate in the mesh.

addVertexWithDelaunayRefinement

Add a vertex in a face with Delaunay refinement of neighboring faces All neighboring faces sharing a vertex will be refined to satisfy the Delaunay condition

advancedEdit

Applies an advance editing on the edited mesh, see QgsMeshAdvancedEditing

canBeMerged

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

changeCoordinates

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

changeXYValues

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

changeZValues

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

checkConsistency

Return True if the edited mesh is consistent

createZValueDatasetGroup

Creates and returns a scalar dataset group with value on vertex that is can be used to access the Z value of the edited mesh.

edgeCanBeFlipped

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

edgeIsClose

Returns True if an edge of face is closest than the tolerance from the point in triangular mesh coordinate Returns also the face index and the edge position in faceIndex and edgePosition

extent

Returns the extent of the edited mesh

faceCanBeAdded

Returns True if a face can be added to the mesh

faceCanBeSplit

Returns True if face with index faceIndex can be split

fixError

Tries to fix the topological error in the mesh.

flipEdge

Flips edge (vertexIndex1, vertexIndex2)

freeVerticesIndexes

Returns all the free vertices indexes

initialize

Initializes the mesh editor and returns first error if the internal native mesh has topological errors

initializeWithErrorsFix

Initializes the mesh editor.

isFaceGeometricallyCompatible

Returns True if the face does not intersect or contains any other elements (faces or vertices) The topological compatibility is not checked

isModified

Returns whether the mesh has been modified

isVertexFree

Returns whether the vertex with index vertexIndex is a free vertex

isVertexOnBoundary

Returns whether the vertex with index vertexIndex is on a boundary

maximumVerticesPerFace

Returns the maximum count of vertices per face that the mesh can support

merge

Merges faces separated by vertices with indexes vertexIndex1 and vertexIndex2

reindex

Reindexes the mesh, that is remove unusued index of face and vertices, this operation void the undo/redo stack.

removeFaces

Removes faces faces to the mesh, returns topological errors if this operation fails (operation is not realized)

removeVerticesFillHoles

Removes vertices with indexes in the list verticesToRemoveIndexes in the mesh the surrounding faces AND fills the freed space.

removeVerticesWithoutFillHoles

Removes vertices with indexes in the list verticesToRemoveIndexes in the mesh removing the surrounding faces without filling the freed space.

splitFaces

Splits faces with index faceIndexes.

stopEditing

Stops editing

validFacesCount

Returns the count of valid faces, that is non void faces in the mesh

validVerticesCount

Returns the count of valid vertices, that is non void vertices in the mesh

Signals

meshEdited

Emitted when the mesh is edited

class qgis.core.QgsMeshEditor[source]

Bases: QObject

__init__(meshLayer: QgsMeshLayer | None)

Constructor with a specified layer meshLayer

Parameters:

meshLayer (Optional[QgsMeshLayer])

addFace(self, vertexIndexes: Iterable[int]) QgsMeshEditingError[source]

Adds a face face to the mesh with vertex indexes vertexIndexes, returns topological errors if this operation fails (operation is not realized)

Parameters:

vertexIndexes (Iterable[int])

Return type:

QgsMeshEditingError

addPointsAsVertices(self, point: Iterable[QgsPoint], tolerance: float) int[source]

Adds points as vertices in triangular mesh coordinate in the mesh. Vertex is effectivly added if the transform from triangular coordinate to layer coordinate succeeds or if any vertices are next the added vertex (under tolerance distance). The method returns the number of vertices effectivly added.

Note

this operation remove including face if exists and replace it by new faces surrounding the vertex if the mesh hasn’t topological error before this operation, the toological operation always succeed

Parameters:
  • point (Iterable[QgsPoint])

  • tolerance (float)

Return type:

int

addVertexWithDelaunayRefinement(self, vertex: QgsPoint, tolerance: float)[source]

Add a vertex in a face with Delaunay refinement of neighboring faces All neighboring faces sharing a vertex will be refined to satisfy the Delaunay condition

Added in version 3.42.

Parameters:
advancedEdit(self, editing: QgsMeshAdvancedEditing | None)[source]

Applies an advance editing on the edited mesh, see QgsMeshAdvancedEditing

Parameters:

editing (Optional[QgsMeshAdvancedEditing])

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

changeCoordinates(self, verticesIndexes: Iterable[int], newCoordinates: Iterable[QgsPoint])[source]

Changes the (X,Y,Z) coordinates values of the vertices with indexes in vertices indexes with the values in newValues. The caller has the responsibility to check if changing the vertices coordinates does not lead to topological errors New coordinates are in layer CRS.

Parameters:
  • verticesIndexes (Iterable[int])

  • newCoordinates (Iterable[QgsPoint])

changeXYValues(self, verticesIndexes: Iterable[int], newValues: Iterable[QgsPointXY])[source]

Changes the (X,Y) coordinates values of the vertices with indexes in verticesIndexes with the values in newValues. The caller has the responsibility to check if changing the vertices coordinates does not lead to topological errors. New values are in layer CRS.

Parameters:
  • verticesIndexes (Iterable[int])

  • newValues (Iterable[QgsPointXY])

changeZValues(self, verticesIndexes: Iterable[int], newValues: Iterable[float])[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])

checkConsistency(self, error: QgsMeshEditingError) bool[source]

Return True if the edited mesh is consistent

Parameters:

error (QgsMeshEditingError)

Return type:

bool

createZValueDatasetGroup(self) QgsMeshDatasetGroup | None[source]

Creates and returns a scalar dataset group with value on vertex that is can be used to access the Z value of the edited mesh. The caller takes ownership.

Return type:

Optional[QgsMeshDatasetGroup]

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

edgeIsClose(self, point: QgsPointXY, tolerance: float)[source]

Returns True if an edge of face is closest than the tolerance from the point in triangular mesh coordinate Returns also the face index and the edge position in faceIndex and edgePosition

Parameters:
extent(self) QgsRectangle[source]

Returns the extent of the edited mesh

Return type:

QgsRectangle

faceCanBeAdded(self, face: Iterable[int]) bool[source]

Returns True if a face can be added to the mesh

Note

All vertices related to this face must be already in the mesh.

Parameters:

face (Iterable[int])

Return type:

bool

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

Returns True if face with index faceIndex can be split

Parameters:

faceIndex (int)

Return type:

bool

fixError(self, error: QgsMeshEditingError) bool[source]

Tries to fix the topological error in the mesh. Returns False if the fix fails

Added in version 3.28.

Parameters:

error (QgsMeshEditingError)

Return type:

bool

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

Flips edge (vertexIndex1, vertexIndex2)

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

freeVerticesIndexes(self) List[int]

Returns all the free vertices indexes

Return type:

List[int]

initialize(self) QgsMeshEditingError[source]

Initializes the mesh editor and returns first error if the internal native mesh has topological errors

Return type:

QgsMeshEditingError

initializeWithErrorsFix(self) QgsMeshEditingError[source]

Initializes the mesh editor. If topological errors occur,tries to fix these errors and returns error if there is one that couldn’t be fixed

Added in version 3.28.

Return type:

QgsMeshEditingError

isFaceGeometricallyCompatible(self, face: Iterable[int]) bool[source]

Returns True if the face does not intersect or contains any other elements (faces or vertices) The topological compatibility is not checked

Parameters:

face (Iterable[int])

Return type:

bool

isModified(self) bool[source]

Returns whether the mesh has been modified

Return type:

bool

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

Returns whether the vertex with index vertexIndex is a free vertex

Parameters:

vertexIndex (int)

Return type:

bool

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

Returns whether the vertex with index vertexIndex is on a boundary

Parameters:

vertexIndex (int)

Return type:

bool

maximumVerticesPerFace(self) int[source]

Returns the maximum count of vertices per face that the mesh can support

Return type:

int

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

Merges faces separated by vertices with indexes vertexIndex1 and vertexIndex2

Parameters:
  • vertexIndex1 (int)

  • vertexIndex2 (int)

signal meshEdited[source]

Emitted when the mesh is edited

reindex(self, renumbering: bool) bool[source]

Reindexes the mesh, that is remove unusued index of face and vertices, this operation void the undo/redo stack.

If renumbering is true, a renumbering is operated to optimize the vertices indexes.

Returns False if the operation fail.

Parameters:

renumbering (bool)

Return type:

bool

removeFaces(self, facesToRemove: Iterable[int]) QgsMeshEditingError[source]

Removes faces faces to the mesh, returns topological errors if this operation fails (operation is not realized)

Parameters:

facesToRemove (Iterable[int])

Return type:

QgsMeshEditingError

removeVerticesFillHoles(self, verticesToRemoveIndexes: Iterable[int]) List[int]

Removes vertices with indexes in the list verticesToRemoveIndexes in the mesh the surrounding faces AND fills the freed space.

This operation fills holes by a Delaunay triangulation using the surrounding vertices. Some vertices could no be deleted to avoid topological error even with hole filling (can not be detected before execution). A list of the remaining vertex indexes is returned.

Parameters:

verticesToRemoveIndexes (Iterable[int])

Return type:

List[int]

removeVerticesWithoutFillHoles(self, verticesToRemoveIndexes: Iterable[int]) QgsMeshEditingError[source]

Removes vertices with indexes in the list verticesToRemoveIndexes in the mesh removing the surrounding faces without filling the freed space.

If removing these vertices leads to a topological errors, the method will return the corresponding error and the operation is canceled

Parameters:

verticesToRemoveIndexes (Iterable[int])

Return type:

QgsMeshEditingError

splitFaces(self, faceIndexes: Iterable[int]) int[source]

Splits faces with index faceIndexes. Only faces that can be split are split. Returns the count of faces effictively split

Parameters:

faceIndexes (Iterable[int])

Return type:

int

stopEditing(self)[source]

Stops editing

validFacesCount(self) int[source]

Returns the count of valid faces, that is non void faces in the mesh

Return type:

int

validVerticesCount(self) int[source]

Returns the count of valid vertices, that is non void vertices in the mesh

Return type:

int