Class: QgsMeshLayer

class qgis.core.QgsMeshLayer(path: str = '', baseName: str = '', providerLib: str = '', options: QgsMeshLayer.LayerOptions = QgsMeshLayer.LayerOptions())

Bases: QgsMapLayer

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 (str = '') – The path or url of the parameter. Typically this encodes parameters used by the data provider as url query items.

  • baseName (str = '') – The name used to represent the layer in the legend

  • providerLib (str = '') – The name of the data provider, e.g., “mesh_memory”, “mdal”

  • options (QgsMeshLayer.LayerOptions = QgsMeshLayer.LayerOptions()) – general mesh layer options

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.

section mesh_providers Mesh data providers

subsection mesh_memory 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. Data can be populated by setMesh(const QString &vertices, const QString &faces), where vertices and faces is comma separated coordinates and connections for mesh. E.g. to create mesh with one quad and one triangle

QString 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"
  );
  :py:class:`.QgsMeshLayer` *scratchLayer = new QgsMeshLayer(uri, "My Scratch layer", "memory_mesh");

subsection mdal 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.

QString uri = "test/land.2dm";
:py:class:`.QgsMeshLayer` *scratchLayer = new QgsMeshLayer(uri, "My Scratch Layer",  "mdal");

Note

The API is considered EXPERIMENTAL and can be changed without a notice

Methods

appendError

childEvent

clone

rtype

QgsMeshLayer

connectNotify

createMapRenderer

param rendererContext

customEvent

dataProvider

QgsMeshLayer cannot be copied.

datasetValue

Interpolates the value on the given point from given dataset.

decodedSource

param source

disconnectNotify

encodedSource

param source

extent

rtype

QgsRectangle

formatTime

Returns (date) time in hours formatted to human readable form

hasDependencyCycle

isSignalConnected

providerType

Returns the provider type for this layer

readCommonStyle

readCustomProperties

readStyleManager

readSymbology

param node

readXml

param layer_node

receivers

reload

rendererSettings

Returns renderer settings

sender

senderSignalIndex

setError

setExtent

setProviderType

setRendererSettings

Sets new renderer settings

setTimeSettings

Sets time format settings

setTransformContext

Sets the coordinate transform context to transformContext.

setValid

timeSettings

Returns time format settings

timerEvent

writeCommonStyle

writeCustomProperties

writeStyleManager

writeSymbology

param node

writeXml

param layer_node

Signals

activeScalarDatasetChanged

Emitted when active scalar dataset is changed

activeVectorDatasetChanged

Emitted when active vector dataset is changed

timeSettingsChanged

Emitted when time format is changed

class LayerOptions(transformContext: QgsCoordinateTransformContext = QgsCoordinateTransformContext())

Bases: sip.wrapper

Constructor for LayerOptions with optional transformContext.

Note

transformContext argument was added in QGIS 3.8

QgsMeshLayer.LayerOptions(QgsMeshLayer.LayerOptions)

Parameters

transformContext (QgsCoordinateTransformContext = QgsCoordinateTransformContext()) –

skipCrsValidation
transformContext
activeScalarDatasetChanged

Emitted when active scalar dataset is changed

New in version 3.4: [signal]

Parameters

index (QgsMeshDatasetIndex) –

activeVectorDatasetChanged

Emitted when active vector dataset is changed

New in version 3.4: [signal]

Parameters

index (QgsMeshDatasetIndex) –

appendError()
childEvent()
clone(self) → QgsMeshLayer
Return type

QgsMeshLayer

connectNotify()
createMapRenderer(self, rendererContext: QgsRenderContext) → QgsMapLayerRenderer
Parameters

rendererContext (QgsRenderContext) –

Return type

QgsMapLayerRenderer

customEvent()
dataProvider(self) → QgsMeshDataProvider

QgsMeshLayer cannot be copied.

Return type

QgsMeshDataProvider

datasetValue(self, index: QgsMeshDatasetIndex, point: QgsPointXY) → QgsMeshDatasetValue

Interpolates the value on the given point from given dataset.

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

Parameters
  • index (QgsMeshDatasetIndex) – dataset index specifying group and dataset to extract value from

  • point (QgsPointXY) – point to query in map coordinates

Return type

QgsMeshDatasetValue

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

New in version 3.4.

decodedSource(self, source: str, provider: str, context: QgsReadWriteContext) → str
Parameters
Return type

str

disconnectNotify()
encodedSource(self, source: str, context: QgsReadWriteContext) → str
Parameters
Return type

str

extent(self) → QgsRectangle
Return type

QgsRectangle

formatTime(self, hours: float) → str

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

New in version 3.8.

hasDependencyCycle()
isSignalConnected()
providerType(self) → str

Returns the provider type for this layer

Return type

str

readCommonStyle()
readCustomProperties()
readStyleManager()
readSymbology(self, node: QDomNode, errorMessage: str, context: QgsReadWriteContext, categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → bool
Parameters
Return type

bool

readXml(self, layer_node: QDomNode, context: QgsReadWriteContext) → bool
Parameters
Return type

bool

receivers()
reload(self)
rendererSettings(self) → QgsMeshRendererSettings

Returns renderer settings

Return type

QgsMeshRendererSettings

sender()
senderSignalIndex()
setError()
setExtent()
setProviderType()
setRendererSettings(self, settings: QgsMeshRendererSettings)

Sets new renderer settings

Parameters

settings (QgsMeshRendererSettings) –

setTimeSettings(self, settings: QgsMeshTimeSettings)

Sets time format settings

New in version 3.8.

Parameters

settings (QgsMeshTimeSettings) –

setTransformContext(self, transformContext: QgsCoordinateTransformContext)

Sets the coordinate transform context to transformContext.

New in version 3.8.

Parameters

transformContext (QgsCoordinateTransformContext) –

setValid()
timeSettings(self) → QgsMeshTimeSettings

Returns time format settings

New in version 3.8.

Return type

QgsMeshTimeSettings

timeSettingsChanged

Emitted when time format is changed

New in version 3.8: [signal]

timerEvent()
writeCommonStyle()
writeCustomProperties()
writeStyleManager()
writeSymbology(self, node: QDomNode, doc: QDomDocument, errorMessage: str, context: QgsReadWriteContext, categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → bool
Parameters
Return type

bool

writeXml(self, layer_node: QDomNode, doc: QDomDocument, context: QgsReadWriteContext) → bool
Parameters
Return type

bool