Class: QgsMeshEditor

class qgis.core.QgsMeshEditor

Bases: PyQt5.QtCore.QObject

Class that makes edit operation on a mesh

New in version 3.22.

QgsMeshEditor(meshLayer: QgsMeshLayer) Constructor with a specified layer meshLayer

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.

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

childEvent

connectNotify

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.

customEvent

disconnectNotify

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

isSignalConnected

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

receivers

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.

sender

senderSignalIndex

splitFaces

Splits faces with index faceIndexes.

stopEditing

Stops editing

timerEvent

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

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

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

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

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

advancedEdit(self, editing: QgsMeshAdvancedEditing)

Applies an advance editing on the edited mesh, see QgsMeshAdvancedEditing

Parameters:

editing (QgsMeshAdvancedEditing) –

canBeMerged(self, vertexIndex1: int, vertexIndex2: int) bool

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

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

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

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

Return True if the edited mesh is consistent

Parameters:

error (QgsMeshEditingError) –

Return type:

bool

childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
createZValueDatasetGroup(self) QgsMeshDatasetGroup

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:

QgsMeshDatasetGroup

customEvent(self, QEvent)
disconnectNotify(self, QMetaMethod)
edgeCanBeFlipped(self, vertexIndex1: int, vertexIndex2: int) bool

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) Tuple[bool, int, int]

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

Tuple[bool, int, int]

extent(self) QgsRectangle

Returns the extent of the edited mesh

Return type:

QgsRectangle

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

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

Returns True if face with index faceIndex can be split

Parameters:

faceIndex (int) –

Return type:

bool

fixError(self, error: QgsMeshEditingError) bool

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

New in version 3.28.

Parameters:

error (QgsMeshEditingError) –

Return type:

bool

flipEdge(self, vertexIndex1: int, vertexIndex2: int)

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

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

Return type:

QgsMeshEditingError

initializeWithErrorsFix(self) QgsMeshEditingError

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

New in version 3.28.

Return type:

QgsMeshEditingError

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

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

Returns whether the mesh has been modified

Return type:

bool

isSignalConnected(self, QMetaMethod) bool
isVertexFree(self, vertexIndex: int) bool

Returns whether the vertex with index vertexIndex is a free vertex

Parameters:

vertexIndex (int) –

Return type:

bool

isVertexOnBoundary(self, vertexIndex: int) bool

Returns whether the vertex with index vertexIndex is on a boundary

Parameters:

vertexIndex (int) –

Return type:

bool

maximumVerticesPerFace(self) int

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

Return type:

int

merge(self, vertexIndex1: int, vertexIndex2: int)

Merges faces separated by vertices with indexes vertexIndex1 and vertexIndex2

Parameters:
  • vertexIndex1 (int) –

  • vertexIndex2 (int) –

meshEdited

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

receivers(self, PYQT_SIGNAL) int
reindex(self, renumbering: bool) bool

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

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

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

sender(self) QObject
senderSignalIndex(self) int
splitFaces(self, faceIndexes: Iterable[int]) int

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)

Stops editing

timerEvent(self, QTimerEvent)
validFacesCount(self) int

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

Return type:

int

validVerticesCount(self) int

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

Return type:

int