Class: QgsMeshLayer¶
Represents a mesh layer supporting display of data on structured or unstructured meshes.
The QgsMeshLayer
is instantiated by specifying the name of a
data provider, such as mdal, and url defining the specific data set to
connect to. The vector layer constructor in turn instantiates a
QgsMeshDataProvider
subclass corresponding to the provider
type, and passes it the url. The data provider connects to the data
source.
The QgsMeshLayer
provides a common interface to the
different data types. It does not yet support editing transactions.
The main data providers supported by QGIS are listed below.
Mesh data providers¶
Memory data providerType (mesh_memory)¶
The memory data provider is used to construct in memory data, for example scratch data. There is no inherent persistent storage of the data. The data source uri is constructed where vertices and faces are comma separated coordinates and connections for the mesh. E.g. to create a mesh with one quad and one triangle
uri = "1.0, 2.0 \n" \
"2.0, 2.0 \n" \
"3.0, 2.0 \n" \
"2.0, 3.0 \n" \
"1.0, 3.0 \n" \
"---" \
"0, 1, 3, 4 \n" \
"1, 2, 3 \n"
scratchLayer = QgsMeshLayer(uri, "My Scratch layer", "mesh_memory")
MDAL data provider (mdal)¶
Accesses data using the MDAL drivers (https://github.com/lutraconsulting/MDAL). The url is the MDAL connection string. QGIS must be built with MDAL support to allow this provider.
uri = "test/land.2dm"
scratchLayer = QgsMeshLayer(uri, "My Scratch Layer", "mdal")
Note
The API is considered EXPERIMENTAL and can be changed without a notice
Added in version 3.2.
Class Hierarchy¶
Base classes¶
Base class for all map layer types. |
|
Interface for classes which can generate elevation profiles. |
Abstract Methods
Sets the coordinate transform context to transformContext. |
Methods
Returns dataset index from active scalar group depending on the time range. |
|
Returns current active scalar dataset index for current renderer context. |
|
Returns dataset index from active vector group depending on the time range If the temporal properties is not active, return the static dataset |
|
Adds datasets to the mesh from file with path. |
|
Returns whether the faces are active for particular dataset |
|
Returns the index of the snapped point on the mesh element closest to point intersecting with the searching area defined by point and searchRadius The position of the snapped point on the closest element is stored in projectedPoint |
|
Commits editing of the mesh frame, Rebuilds the triangular mesh and its spatial index with transform, Continue editing with the same mesh editor if continueEditing is True |
|
Returns whether the mesh contains at mesh elements of given type |
|
Returns the value of 1D mesh dataset defined on edge that are in the search area defined by point ans searchRadius |
|
Returns the 3d values of stacked 3d mesh defined by the given point |
|
Returns N vector/scalar values from the face index from the dataset for 3d stacked meshes |
|
Returns the dataset count in the dataset groups |
|
Returns the dataset groups count handle by the layer |
|
Returns the dataset groups metadata |
|
Returns the root items of the dataset group tree item |
|
Returns the list of indexes of dataset groups handled by the layer |
|
Returns dataset index from datasets group depending on the relative time from the layer reference time. |
|
Returns dataset index from datasets group depending on the time range. |
|
Returns a list of dataset indexes from datasets group that are in a interval time from the layer reference time. |
|
Returns the dataset metadata |
|
Returns the relative time of the dataset from the reference time of its group |
|
Returns the relative time (in milliseconds) of the dataset from the reference time of its group |
|
Returns vector/scalar value associated with the index from the dataset To read multiple continuous values, use |
|
Returns N vector/scalar values from the index from the dataset |
|
Checks whether that datasets path is already added to this mesh layer. |
|
Returns the list of indexes of enables dataset groups handled by the layer |
|
Returns the extra dataset groups count handle by the layer |
|
Returns the first valid time step of the dataset groups, invalid QgInterval if no time step is present |
|
Returns (date) time in hours formatted to human readable form |
|
Returns N vector/scalar values from the face index from the dataset for 3d stacked meshes |
|
Access to labeling configuration. |
|
Returns whether the layer contains labels which are enabled and should be drawn. |
|
Returns the edges count of the mesh frame |
|
Returns a pointer to the mesh editor own by the mesh layer |
|
Returns the faces count of the mesh frame |
|
Returns the vertices count of the mesh frame |
|
Extracts minimum and maximum value for active scalar dataset on mesh faces. |
|
Re-indexes the faces and vertices, and renumber the indexes if renumber is |
|
Removes datasets from the mesh with given name. |
|
Returns renderer settings |
|
Reset the dataset group tree item to default from provider |
|
Rolls Back editing of the mesh frame. |
|
Saves datasets group on file with the specified driver |
|
Returns a list of faces indexes that meet the condition defined by expression with the context expressionContext |
|
Returns a list of vertex indexes that meet the condition defined by expression with the context expressionContext |
|
Sets the root items of the dataset group tree item. |
|
Sets labeling configuration. |
|
Sets whether labels should be enabled for the layer. |
|
Sets the reference time of the layer |
|
Sets new renderer settings |
|
Sets the method used to match the temporal dataset from a requested time, see |
|
Sets time format settings |
|
Returns the position of the snapped point on the mesh element closest to point intersecting with the searching area defined by point and searchRadius |
|
Starts editing of the mesh frame. |
|
Returns the static scalar dataset index that is rendered if the temporal properties is not active. |
|
Returns the static vector dataset index that is rendered if the temporal properties is not active. |
|
Stops editing of the mesh, re-indexes the faces and vertices, rebuilds the triangular mesh and its spatial index with transform, clean the undostack |
|
Returns time format settings |
|
Gets native mesh and updates (creates if it doesn't exist) the base triangular mesh |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsMeshLayer. See the FAQ for more details.
Returns whether the mesh frame has been modified since the last save |
Signals
Emitted when active scalar group dataset is changed |
|
Emitted when active vector group dataset is changed |
|
Emitted when the mesh layer is reloaded, see |
|
Emitted when time format is changed |
- class qgis.core.QgsMeshLayer[source]¶
Bases:
QgsMapLayer
,QgsAbstractProfileSource
- __init__(path: str | None = '', baseName: str | None = '', providerLib: str | None = '', options: QgsMeshLayer.LayerOptions = QgsMeshLayer.LayerOptions())
Constructor - creates a mesh layer
The QgsMeshLayer is constructed by instantiating a data provider. The provider interprets the supplied path (url) of the data source to connect to and access the data.
- Parameters:
path (Optional[str] = '') – The path or url of the parameter. Typically this encodes parameters used by the data provider as url query items.
baseName (Optional[str] = '') – The name used to represent the layer in the legend
providerLib (Optional[str] = '') – The name of the data provider, e.g., “mesh_memory”, “mdal”
options (QgsMeshLayer.LayerOptions = QgsMeshLayer.LayerOptions()) – general mesh layer options
- class LayerOptions¶
Bases:
object
Setting options for loading mesh layers.
- skipCrsValidation: bool¶
Controls whether the layer is allowed to have an invalid/unknown CRS.
If
True
, then no validation will be performed on the layer’s CRS and the layer layer’scrs()
may beinvalid()
(i.e. the layer will have no georeferencing available and will be treated as having purely numerical coordinates).If
False
(the default), the layer’s CRS will be validated usingQgsCoordinateReferenceSystem.validate()
, which may cause a blocking, user-facing dialog asking users to manually select the correct CRS for the layer.Added in version 3.10.
- activeScalarDatasetAtTime(self, timeRange: QgsDateTimeRange, group: int = -1) QgsMeshDatasetIndex [source]¶
Returns dataset index from active scalar group depending on the time range. If the temporal properties is not active, return the static dataset
Since QGIS 3.38, the
group
argument can be used to specify a fixed group to use. If this is not specified, then the active group from the layer’s renderer will be used.Note
the returned dataset index depends on the matching method, see
setTemporalMatchingMethod()
Added in version 3.14.
- Parameters:
timeRange (QgsDateTimeRange)
group (int = -1)
- Return type:
- signal activeScalarDatasetGroupChanged(index: int)[source]¶
Emitted when active scalar group dataset is changed
Added in version 3.14.
- Parameters:
index (int)
- activeScalarDatasetIndex(self, rendererContext: QgsRenderContext) QgsMeshDatasetIndex [source]¶
Returns current active scalar dataset index for current renderer context.
Added in version 3.42.
- Parameters:
rendererContext (QgsRenderContext)
- Return type:
- activeVectorDatasetAtTime(self, timeRange: QgsDateTimeRange, group: int = -1) QgsMeshDatasetIndex [source]¶
Returns dataset index from active vector group depending on the time range If the temporal properties is not active, return the static dataset
Since QGIS 3.38, the
group
argument can be used to specify a fixed group to use. If this is not specified, then the active group from the layer’s renderer will be used.Note
the returned dataset index depends on the matching method, see
setTemporalMatchingMethod()
Added in version 3.14.
- Parameters:
timeRange (QgsDateTimeRange)
group (int = -1)
- Return type:
- signal activeVectorDatasetGroupChanged(index: int)[source]¶
Emitted when active vector group dataset is changed
Added in version 3.14.
- Parameters:
index (int)
- addDatasets(self, path: str | None, defaultReferenceTime: QDateTime | datetime.datetime = QDateTime()) bool [source]¶
Adds datasets to the mesh from file with
path
. Use the the timedefaultReferenceTime
as reference time is not provided in the file- Parameters:
path (Optional[str]) – the path to the datasets file
defaultReferenceTime (Union[QDateTime, datetime.datetime] = QDateTime()) – reference time used if not provided in the file
- Return type:
bool
- Returns:
whether the dataset is added
Added in version 3.14.
- addDatasets(self, datasetGroup: QgsMeshDatasetGroup | None) bool [source]
Adds extra datasets to the mesh. Take ownership.
- Parameters:
datasetGroup (Optional[QgsMeshDatasetGroup]) – the extra dataset group
- Return type:
bool
- Returns:
whether the dataset is effectively added
Added in version 3.16.
- areFacesActive(self, index: QgsMeshDatasetIndex, faceIndex: int, count: int) QgsMeshDataBlock [source]¶
Returns whether the faces are active for particular dataset
- Parameters:
index (QgsMeshDatasetIndex) – index of the dataset
faceIndex (int) – index of the face
count (int) – number of values to return
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes are different from the data provider indexes.
Added in version 3.16.
- Return type:
- closestElement(self, elementType: QgsMesh.ElementType, point: QgsPointXY, searchRadius: float)[source]¶
Returns the index of the snapped point on the mesh element closest to
point
intersecting with the searching area defined bypoint
andsearchRadius
The position of the snapped point on the closest element is stored inprojectedPoint
For vertex, the snapped position is the vertex position For edge, the snapped position is the projected point on the edge, extremity of edge if outside the edge For face, the snapped position is the centroid of the face The snapped position is in map coordinates.
Note
It uses previously cached and indexed triangular mesh and so if the layer has not been rendered previously (e.g. when used in a script) it returns empty
QgsPointXY
See also
Note
This is similar to the
snapOnElement()
method, except it also returns the index of the snapped pointSee also
- Parameters:
elementType (QgsMesh.ElementType) – the type of element to snap
point (QgsPointXY) – the center of the search area in map coordinates
searchRadius (float) -> (int) – the radius of the search area in map units
- Returns:
index of the snapped point on the closest element, -1 if no element of type
elementType
projectedPoint: the position of the snapped point on the closest element, empty
QgsPointXY
if no element of typeelementType
Added in version 3.44.
- commitFrameEditing(self, transform: QgsCoordinateTransform, continueEditing: bool = True) bool [source]¶
Commits editing of the mesh frame, Rebuilds the triangular mesh and its spatial index with
transform
, Continue editing with the same mesh editor ifcontinueEditing
is True- Return type:
bool
- Returns:
True
if the commit succeeds
Added in version 3.22.
- Parameters:
transform (QgsCoordinateTransform)
continueEditing (bool = True)
- contains(self, type: QgsMesh.ElementType) bool [source]¶
Returns whether the mesh contains at mesh elements of given type
Added in version 3.22.
- Parameters:
type (QgsMesh.ElementType)
- Return type:
bool
- dataset1dValue(self, index: QgsMeshDatasetIndex, point: QgsPointXY, searchRadius: float) QgsMeshDatasetValue [source]¶
Returns the value of 1D mesh dataset defined on edge that are in the search area defined by point ans searchRadius
Note
It uses previously cached and indexed triangular mesh and so if the layer has not been rendered previously (e.g. when used in a script) it returns NaN value
See also
- Parameters:
index (QgsMeshDatasetIndex) – dataset index specifying group and dataset to extract value from
point (QgsPointXY) – the center point of the search area
searchRadius (float) – the radius of the searc area in map unit
- Return type:
- Returns:
interpolated value at the projected point. Returns NaN values for values outside the mesh layer and in case triangular mesh was not previously used for rendering
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes are different from the data provider indexes.
Added in version 3.14.
- dataset3dValue(self, index: QgsMeshDatasetIndex, point: QgsPointXY) QgsMesh3DDataBlock [source]¶
Returns the 3d values of stacked 3d mesh defined by the given point
Note
It uses previously cached and indexed triangular mesh and so if the layer has not been rendered previously (e.g. when used in a script) it returns NaN value
See also
- Parameters:
index (QgsMeshDatasetIndex) – dataset index specifying group and dataset to extract value from
point (QgsPointXY) – point to query in map coordinates
- Return type:
- Returns:
all 3d stacked values that belong to face defined by given point. Returns invalid block for point outside the mesh layer or in case triangular mesh was not previously used for rendering or for datasets that do not have type DataOnVolumes
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes are different from the data provider indexes.
Added in version 3.12.
- dataset3dValues(self, index: QgsMeshDatasetIndex, faceIndex: int, count: int) QgsMesh3DDataBlock [source]¶
Returns N vector/scalar values from the face index from the dataset for 3d stacked meshes
See
QgsMeshDatasetMetadata.isVector()
to check if the returned value is vector or scalarreturns invalid block for DataOnFaces and DataOnVertices.
- Parameters:
index (QgsMeshDatasetIndex) – index of the dataset
faceIndex (int) – index of the face
count (int) – number of values to return
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes can be different from the data provider indexes.
Added in version 3.16.
- Return type:
- datasetCount(self, index: QgsMeshDatasetIndex) int [source]¶
Returns the dataset count in the dataset groups
- Parameters:
index (QgsMeshDatasetIndex) – index of the dataset in the group
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes can be different from the data provider indexes.
Added in version 3.16.
- Return type:
int
- datasetGroupCount(self) int [source]¶
Returns the dataset groups count handle by the layer
Added in version 3.16.
- Return type:
int
- datasetGroupMetadata(self, index: QgsMeshDatasetIndex) QgsMeshDatasetGroupMetadata [source]¶
Returns the dataset groups metadata
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes can be different from the data provider indexes.
Added in version 3.16.
- Parameters:
index (QgsMeshDatasetIndex)
- Return type:
- datasetGroupTreeRootItem(self) QgsMeshDatasetGroupTreeItem | None [source]¶
Returns the root items of the dataset group tree item
- Return type:
Optional[QgsMeshDatasetGroupTreeItem]
- Returns:
the root item
Added in version 3.14.
- datasetGroupsIndexes(self) List[int] ¶
Returns the list of indexes of dataset groups handled by the layer
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes can be different from the data provider indexes.
Added in version 3.16.
- Return type:
List[int]
- datasetIndexAtRelativeTime(self, relativeTime: QgsInterval, datasetGroupIndex: int) QgsMeshDatasetIndex [source]¶
Returns dataset index from datasets group depending on the relative time from the layer reference time. Dataset index is valid even the temporal properties is inactive. This method is used for calculation on mesh layer.
- Parameters:
relativeTime (QgsInterval) – the relative from the mesh layer reference time
datasetGroupIndex (int) – the index of the dataset group
- Return type:
- Returns:
dataset index
Note
the returned dataset index depends on the matching method, see
setTemporalMatchingMethod()
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes are different from the data provider indexes.
Added in version 3.16.
- datasetIndexAtTime(self, timeRange: QgsDateTimeRange, datasetGroupIndex: int) QgsMeshDatasetIndex [source]¶
Returns dataset index from datasets group depending on the time range. If the temporal properties is not active, returns invalid dataset index. This method is used for rendering mesh layer.
- Parameters:
timeRange (QgsDateTimeRange) – the time range
datasetGroupIndex (int) – the index of the dataset group
- Return type:
- Returns:
dataset index
Note
the returned dataset index depends on the matching method, see
setTemporalMatchingMethod()
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes are different from the data provider indexes.
Added in version 3.14.
- datasetIndexInRelativeTimeInterval(self, startRelativeTime: QgsInterval, endRelativeTime: QgsInterval, datasetGroupIndex: int) List[QgsMeshDatasetIndex] ¶
Returns a list of dataset indexes from datasets group that are in a interval time from the layer reference time. Dataset index is valid even the temporal properties is inactive. This method is used for calculation on mesh layer.
- Parameters:
startRelativeTime (QgsInterval) – the start time of the relative interval from the reference time.
endRelativeTime (QgsInterval) – the end time of the relative interval from the reference time.
datasetGroupIndex (int) – the index of the dataset group
- Return type:
List[QgsMeshDatasetIndex]
- Returns:
dataset index
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes are different from the data provider indexes.
Added in version 3.22.
- datasetMetadata(self, index: QgsMeshDatasetIndex) QgsMeshDatasetMetadata [source]¶
Returns the dataset metadata
- Parameters:
index (QgsMeshDatasetIndex) – index of the dataset
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes can be different from the data provider indexes.
Added in version 3.16.
- Return type:
- datasetRelativeTime(self, index: QgsMeshDatasetIndex) QgsInterval [source]¶
Returns the relative time of the dataset from the reference time of its group
Added in version 3.16.
- Parameters:
index (QgsMeshDatasetIndex)
- Return type:
- datasetRelativeTimeInMilliseconds(self, index: QgsMeshDatasetIndex) int [source]¶
Returns the relative time (in milliseconds) of the dataset from the reference time of its group
Added in version 3.16.
- Parameters:
index (QgsMeshDatasetIndex)
- Return type:
int
- datasetValue(self, index: QgsMeshDatasetIndex, valueIndex: int) QgsMeshDatasetValue [source]¶
Returns vector/scalar value associated with the index from the dataset To read multiple continuous values, use
datasetValues()
See
QgsMeshDatasetMetadata.isVector()
orQgsMeshDataBlock.type()
to check if the returned value is vector or scalarReturns invalid value for DataOnVolumes
- Parameters:
index (
QgsMeshDatasetIndex
) – index of the datasetvalueIndex (int) – index of the value
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes can be different from the data provider indexes.
Added in version 3.16.
- Return type:
- datasetValue(self, index: QgsMeshDatasetIndex, point: QgsPointXY, searchRadius: float = 0) QgsMeshDatasetValue [source]
Interpolates the value on the given point from given dataset. For 3D datasets, it uses
dataset3dValue()
, n For 1D datasets, it usesdataset1dValue()
withsearchRadius
Note
It uses previously cached and indexed triangular mesh and so if the layer has not been rendered previously (e.g. when used in a script) it returns NaN value
See also
- Parameters:
index (
QgsMeshDatasetIndex
) – dataset index specifying group and dataset to extract value frompoint (
QgsPointXY
) – point to query in map coordinatessearchRadius (float = 0) – the radius of the search area in map unit
- Return type:
- Returns:
interpolated value at the point. Returns NaN values for values outside the mesh layer, nodata values and in case triangular mesh was not previously used for rendering
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes are different from the data provider indexes.
Added in version 3.4.
- datasetValues(self, index: QgsMeshDatasetIndex, valueIndex: int, count: int) QgsMeshDataBlock [source]¶
Returns N vector/scalar values from the index from the dataset
See
QgsMeshDatasetMetadata.isVector()
orQgsMeshDataBlock.type()
to check if the returned value is vector or scalarReturns invalid block for DataOnVolumes. Use
QgsMeshLayerUtils.datasetValues()
if you need block for any type of data type- Parameters:
index (QgsMeshDatasetIndex) – index of the dataset
valueIndex (int) – index of the value
count (int) – number of values to return
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes can be different from the data provider indexes.
Added in version 3.16.
- Return type:
- datasetsPathUnique(self, path: str | None) bool [source]¶
Checks whether that datasets path is already added to this mesh layer. Return
True
if the dataset path is not already added.- Parameters:
path (Optional[str]) – the path to the datasets file
- Return type:
bool
- Returns:
whether the datasets path is unique
Added in version 3.42.
- enabledDatasetGroupsIndexes(self) List[int] ¶
Returns the list of indexes of enables dataset groups handled by the layer
Note
indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,…) In the layer scope, those indexes can be different from the data provider indexes.
Added in version 3.16.3.
- Return type:
List[int]
- extraDatasetGroupCount(self) int [source]¶
Returns the extra dataset groups count handle by the layer
Added in version 3.16.
- Return type:
int
- firstValidTimeStep(self) QgsInterval [source]¶
Returns the first valid time step of the dataset groups, invalid QgInterval if no time step is present
Added in version 3.14.
- Return type:
- formatTime(self, hours: float) str [source]¶
Returns (date) time in hours formatted to human readable form
- Parameters:
hours (float) – time in double in hours
- Return type:
str
- Returns:
formatted time string
Added in version 3.8.
- isFaceActive(self, index: QgsMeshDatasetIndex, faceIndex: int) bool [source]¶
Returns N vector/scalar values from the face index from the dataset for 3d stacked meshes
See
QgsMeshDatasetMetadata.isVector()
to check if the returned value is vector or scalarreturns invalid block for DataOnFaces and DataOnVertices.
- Parameters:
index (QgsMeshDatasetIndex)
faceIndex (int)
- Return type:
bool
- virtual isModified(self) bool [source]¶
Returns whether the mesh frame has been modified since the last save
Added in version 3.22.
- Return type:
bool
- labeling(self) QgsAbstractMeshLayerLabeling | None [source]¶
Access to labeling configuration. May be
None
if labeling is not used.Note
Labels will only be rendered if
labelsEnabled()
returnsTrue
.See also
Added in version 3.36.
- Return type:
Optional[QgsAbstractMeshLayerLabeling]
- labelsEnabled(self) bool [source]¶
Returns whether the layer contains labels which are enabled and should be drawn.
- Return type:
bool
- Returns:
True
if layer contains enabled labels
See also
See also
Added in version 3.36.
- meshEdgeCount(self) int [source]¶
Returns the edges count of the mesh frame
Added in version 3.22.
- Return type:
int
- meshEditor(self) QgsMeshEditor | None [source]¶
Returns a pointer to the mesh editor own by the mesh layer
Added in version 3.22.
- Return type:
Optional[QgsMeshEditor]
- meshFaceCount(self) int [source]¶
Returns the faces count of the mesh frame
Note
during mesh editing, some faces can be void and are not included in this returned value
Added in version 3.22.
- Return type:
int
- meshVertexCount(self) int [source]¶
Returns the vertices count of the mesh frame
Note
during mesh editing, some vertices can be void and are not included in this returned value
Added in version 3.22.
- Return type:
int
- minimumMaximumActiveScalarDataset(self, extent: QgsRectangle, datasetIndex: QgsMeshDatasetIndex)[source]¶
Extracts minimum and maximum value for active scalar dataset on mesh faces.
- Parameters:
extent (QgsRectangle) – extent in which intersecting faces are searched for
datasetIndex (
QgsMeshDatasetIndex
) -> (bool) – index for which dataset the values should be extracted
- Returns:
True
if values were extractedmin: minimal value
max: maximal value
Added in version 3.42.
- reindex(self, transform: QgsCoordinateTransform, renumber: bool) bool [source]¶
Re-indexes the faces and vertices, and renumber the indexes if
renumber
isTrue
. rebuilds the triangular mesh and its spatial index withtransform
, clean the undostackReturns
False
if the operation failsAdded in version 3.22.
- Parameters:
transform (QgsCoordinateTransform)
renumber (bool)
- Return type:
bool
- signal reloaded[source]¶
Emitted when the mesh layer is reloaded, see
reload()
Added in version 3.28.
- removeDatasets(self, name: str | None) bool [source]¶
Removes datasets from the mesh with given
name
.- Parameters:
name (Optional[str]) – name of dataset group to remove
- Return type:
bool
- Returns:
whether the dataset is removed
Added in version 3.42.
- rendererSettings(self) QgsMeshRendererSettings [source]¶
Returns renderer settings
- Return type:
- resetDatasetGroupTreeItem(self)[source]¶
Reset the dataset group tree item to default from provider
Added in version 3.14.
- rollBackFrameEditing(self, transform: QgsCoordinateTransform, continueEditing: bool = True) bool [source]¶
Rolls Back editing of the mesh frame. Reload mesh from file, rebuilds the triangular mesh and its spatial index with
transform
, Continue editing with the same mesh editor ifcontinueEditing
isTrue
- Return type:
bool
- Returns:
True
if the rollback succeeds
Added in version 3.22.
- Parameters:
transform (QgsCoordinateTransform)
continueEditing (bool = True)
- saveDataset(self, path: str | None, datasetGroupIndex: int, driver: str | None) bool [source]¶
Saves datasets group on file with the specified
driver
- Parameters:
path (Optional[str]) – the path of the file
datasetGroupIndex (int) – the index of the dataset group
driver (Optional[str]) – the driver to used for saving
- Return type:
bool
- Returns:
false if succeeds
Added in version 3.16.
- selectFacesByExpression(self, expression: QgsExpression) List[int] ¶
Returns a list of faces indexes that meet the condition defined by
expression
with the contextexpressionContext
To express the relation with a face, the expression can be defined with function returning value linked to the current face, like “ $face_area “
Added in version 3.22.
- Parameters:
expression (QgsExpression)
- Return type:
List[int]
- selectVerticesByExpression(self, expression: QgsExpression) List[int] ¶
Returns a list of vertex indexes that meet the condition defined by
expression
with the contextexpressionContext
To express the relation with a vertex, the expression can be defined with function returning value linked to the current vertex, like ” $vertex_z “, “$vertex_as_point”
Added in version 3.22.
- Parameters:
expression (QgsExpression)
- Return type:
List[int]
- setDatasetGroupTreeRootItem(self, rootItem: QgsMeshDatasetGroupTreeItem | None)[source]¶
Sets the root items of the dataset group tree item. Changes active dataset groups if those one are not enabled anymore :
new active scalar dataset group is the first root item enabled child
new active vector dataset group is none
Doesn’t take ownership of the pointed item, the root item is cloned.
- Parameters:
rootItem (Optional[QgsMeshDatasetGroupTreeItem]) – the new root item
Added in version 3.14.
- setLabeling(self, labeling: QgsAbstractMeshLayerLabeling | None)[source]¶
Sets labeling configuration. Takes ownership of the object.
Added in version 3.36.
- Parameters:
labeling (Optional[QgsAbstractMeshLayerLabeling])
- setLabelsEnabled(self, enabled: bool)[source]¶
Sets whether labels should be
enabled
for the layer.Note
Labels will only be rendered if
labelsEnabled()
isTrue
and a labeling object is returned bylabeling()
.See also
See also
Added in version 3.36.
- Parameters:
enabled (bool)
- setReferenceTime(self, referenceTime: QDateTime | datetime.datetime)[source]¶
Sets the reference time of the layer
- Parameters:
referenceTime (Union[QDateTime, datetime.datetime]) – the reference time
Added in version 3.14.
- setRendererSettings(self, settings: QgsMeshRendererSettings, repaint: bool = True)[source]¶
Sets new renderer settings
- Parameters:
settings (QgsMeshRendererSettings)
repaint (bool = True) – should the update of renderer settings trigger repaint and emit rendererChanged signal
- setTemporalMatchingMethod(self, matchingMethod: QgsMeshDataProviderTemporalCapabilities.MatchingTemporalDatasetMethod)[source]¶
Sets the method used to match the temporal dataset from a requested time, see
activeVectorDatasetAtTime()
- Parameters:
matchingMethod (QgsMeshDataProviderTemporalCapabilities.MatchingTemporalDatasetMethod) – the matching method
Added in version 3.14.
- setTimeSettings(self, settings: QgsMeshTimeSettings)[source]¶
Sets time format settings
Added in version 3.8.
- Parameters:
settings (QgsMeshTimeSettings)
- abstract setTransformContext(self, transformContext: QgsCoordinateTransformContext)[source]¶
Sets the coordinate transform context to
transformContext
.Added in version 3.8.
- Parameters:
transformContext (QgsCoordinateTransformContext)
- snapOnElement(self, elementType: QgsMesh.ElementType, point: QgsPointXY, searchRadius: float) QgsPointXY [source]¶
Returns the position of the snapped point on the mesh element closest to
point
intersecting with the searching area defined bypoint
andsearchRadius
For vertex, the snapped position is the vertex position For edge, the snapped position is the projected point on the edge, extremity of edge if outside the edge For face, the snapped position is the centroid of the face The returned position is in map coordinates.
Note
It uses previously cached and indexed triangular mesh and so if the layer has not been rendered previously (e.g. when used in a script) it returns empty
QgsPointXY
See also
- Parameters:
elementType (QgsMesh.ElementType) – the type of element to snap
point (QgsPointXY) – the center of the search area in map coordinates
searchRadius (float) – the radius of the search area in map units
- Return type:
- Returns:
the position of the snapped point on the closest element, empty
QgsPointXY
if no element of typeelementType
Added in version 3.14.
- startFrameEditing(self, transform: QgsCoordinateTransform) bool [source]¶
Starts editing of the mesh frame. Coordinate
transform
used to initialize the triangular mesh if needed. This operation will disconnect the mesh layer from the data provider and removes all existing dataset groupAdded in version 3.22.
Deprecated since version 3.28: Use the version with
QgsMeshEditingError
instead.- Parameters:
transform (
QgsCoordinateTransform
)- Return type:
bool
- startFrameEditing(self, transform: QgsCoordinateTransform, fixErrors: bool)[source]
Starts editing of the mesh frame. Coordinate
transform
used to initialize the triangular mesh if needed. This operation will disconnect the mesh layer from the data provider and removes all existing dataset group. ReturnsFalse
if starting fails and theerror
that is the reason (No error, if the mesh is not editable or already in edit mode).If
fixErrors
is set toTrue
, errors will be attempted to be fixed. In that case returnsFalse
if there is an error that could not be fixed and the remainingerror
.Added in version 3.28.
- Parameters:
transform (
QgsCoordinateTransform
)fixErrors (bool) -> (bool)
- staticScalarDatasetIndex(self, group: int = -1) QgsMeshDatasetIndex [source]¶
Returns the static scalar dataset index that is rendered if the temporal properties is not active.
Since QGIS 3.38, the
group
argument can be used to specify a fixed group to use. If this is not specified, then the active group from the layer’s renderer will be used.Added in version 3.14.
- Parameters:
group (int = -1)
- Return type:
- staticVectorDatasetIndex(self, group: int = -1) QgsMeshDatasetIndex [source]¶
Returns the static vector dataset index that is rendered if the temporal properties is not active.
Since QGIS 3.38, the
group
argument can be used to specify a fixed group to use. If this is not specified, then the active group from the layer’s renderer will be used.Added in version 3.14.
- Parameters:
group (int = -1)
- Return type:
- stopFrameEditing(self, transform: QgsCoordinateTransform)[source]¶
Stops editing of the mesh, re-indexes the faces and vertices, rebuilds the triangular mesh and its spatial index with
transform
, clean the undostackAdded in version 3.22.
- Parameters:
transform (QgsCoordinateTransform)
- timeSettings(self) QgsMeshTimeSettings [source]¶
Returns time format settings
Added in version 3.8.
- Return type:
- updateTriangularMesh(self, transform: QgsCoordinateTransform = QgsCoordinateTransform())[source]¶
Gets native mesh and updates (creates if it doesn’t exist) the base triangular mesh
- Parameters:
transform (
QgsCoordinateTransform
= QgsCoordinateTransform()) – Transformation from layer CRS to destination (e.g. map) CRS. With invalid transform, it keeps the native mesh CRS
Added in version 3.14.