QgsMeshLayer class
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Contents
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. 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" ); QgsMeshLayer *scratchLayer = new QgsMeshLayer(uri, "My Scratch layer", "memory_mesh");
MDAL data provider (mdal)
Accesses data using the MDAL drivers (https:/
QString uri = "test/land.2dm"; QgsMeshLayer *scratchLayer = new QgsMeshLayer(uri, "My Scratch Layer", "mdal");
Base classes
- class QgsMapLayer
- Base class for all map layer types.
Public types
- struct LayerOptions
- Setting options for loading mesh layers.
Constructors, destructors, conversion operators
-
QgsMeshLayer(const QString& path = QString(),
const QString& baseName = QString(),
const QString& providerLib = "mesh_memory",
const QgsMeshLayer::
LayerOptions& options = QgsMeshLayer:: LayerOptions()) explicit - Constructor - creates a mesh layer.
- QgsMeshLayer(const QgsMeshLayer& rhs) deleted
- QgsMeshLayer cannot be copied.
Public functions
- auto clone() const -> QgsMeshLayer* override
- Returns a new instance equivalent to this one except for the id which is still unique.
- auto createMapRenderer(QgsRenderContext& rendererContext) -> QgsMapLayerRenderer* override
- Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
- auto dataProvider() -> QgsMeshDataProvider* override
- Returns the layer's data provider, it may be null.
- auto dataProvider() const -> const QgsMeshDataProvider* override
- Returns the layer's data provider in a const-correct manner, it may be null.
- auto datasetValue(const QgsMeshDatasetIndex& index, const QgsPointXY& point) const -> QgsMeshDatasetValue
- Interpolates the value on the given point from given dataset.
- auto decodedSource(const QString& source, const QString& dataProvider, const QgsReadWriteContext& context) const -> QString override
- Called by readLayerXML(), used by derived classes to decode provider's specific data source from project files.
- auto encodedSource(const QString& source, const QgsReadWriteContext& context) const -> QString override
- Called by writeLayerXML(), used by derived classes to encode provider's specific data source to project files.
- auto extent() const -> QgsRectangle override
- Returns the extent of the layer.
- auto nativeMesh() -> QgsMesh*
- Returns native mesh (nullptr before rendering)
- auto nativeMesh() const -> const QgsMesh*
- Returns native mesh (nullptr before rendering)
- auto operator=(QgsMeshLayer const& rhs) -> QgsMeshLayer& deleted
- QgsMeshLayer cannot be copied.
- auto providerType() const -> QString
- Returns the provider type for this layer.
- auto readXml(const QDomNode& layer_node, QgsReadWriteContext& context) -> bool override
- Called by readLayerXML(), used by children to read state specific to them from project files.
- auto rendererCache() -> QgsMeshLayerRendererCache*
- Returns native mesh (nullptr before rendering)
- auto rendererSettings() const -> QgsMeshRendererSettings
- Returns renderer settings.
- void setRendererSettings(const QgsMeshRendererSettings& settings)
- Sets new renderer settings.
- auto triangularMesh() -> QgsTriangularMesh*
- Returns triangular mesh (nullptr before rendering)
- auto triangularMesh() const -> const QgsTriangularMesh*
- Returns triangular mesh (nullptr before rendering)
- auto writeXml(QDomNode& layer_node, QDomDocument& document, const QgsReadWriteContext& context) const -> bool override
- Called by writeLayerXML(), used by children to write state specific to them to project files.
Signals
- void activeScalarDatasetChanged(const QgsMeshDatasetIndex& index)
- Emitted when active scalar dataset is changed.
- void activeVectorDatasetChanged(const QgsMeshDatasetIndex& index)
- Emitted when active vector dataset is changed.
Private functions
- auto isReadOnly() const -> bool override
- Returns true if the provider is in read-only mode.
Function documentation
QgsMeshLayer:: QgsMeshLayer(const QString& path = QString(),
const QString& baseName = QString(),
const QString& providerLib = "mesh_memory",
const QgsMeshLayer:: LayerOptions& options = QgsMeshLayer:: LayerOptions()) explicit
Constructor - creates a mesh layer.
| Parameters | |
|---|---|
| path | The path or url of the parameter. Typically this encodes parameters used by the data provider as url query items. |
| baseName | The name used to represent the layer in the legend |
| providerLib | The name of the data provider, e.g., "mesh_memory", "mdal" |
| options | general mesh layer options |
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.
QgsMeshLayer* QgsMeshLayer:: clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
| Returns | a new layer instance |
|---|
QgsMapLayerRenderer* QgsMeshLayer:: createMapRenderer(QgsRenderContext& rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
const QgsMeshDataProvider* QgsMeshLayer:: dataProvider() const override
Returns the layer's data provider in a const-correct manner, it may be null.
QgsMeshDatasetValue QgsMeshLayer:: datasetValue(const QgsMeshDatasetIndex& index,
const QgsPointXY& point) const
Interpolates the value on the given point from given dataset.
| Parameters | |
|---|---|
| index | dataset index specifying group and dataset to extract value from |
| point | point to query in map coordinates |
| 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 |
QString QgsMeshLayer:: decodedSource(const QString& source,
const QString& dataProvider,
const QgsReadWriteContext& context) const override
Called by readLayerXML(), used by derived classes to decode provider's specific data source from project files.
| Parameters | |
|---|---|
| source | data source to decode, typically read from layer's DOM element "datasource" |
| dataProvider | string identification of data provider (e.g. "ogr"), typically read from layer's DOM element |
| context | reading context (e.g. for conversion between relative and absolute paths) |
| Returns | decoded source, typically to be used as the layer's datasource |
Typically resolving absolute or relative paths, usernames and passwords or drivers prefixes ("HDF5:")
QString QgsMeshLayer:: encodedSource(const QString& source,
const QgsReadWriteContext& context) const override
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to project files.
| Parameters | |
|---|---|
| source | data source to encode, typically QgsMapLayer:: |
| context | writing context (e.g. for conversion between relative and absolute paths) |
| Returns | encoded source, typically to be written in the DOM element "datasource" |
Typically resolving absolute or relative paths, usernames and passwords or drivers prefixes ("HDF5:")
QgsMesh* QgsMeshLayer:: nativeMesh()
Returns native mesh (nullptr before rendering)
const QgsMesh* QgsMeshLayer:: nativeMesh() const
Returns native mesh (nullptr before rendering)
QgsMeshLayerRendererCache* QgsMeshLayer:: rendererCache()
Returns native mesh (nullptr before rendering)
QgsTriangularMesh* QgsMeshLayer:: triangularMesh()
Returns triangular mesh (nullptr before rendering)
const QgsTriangularMesh* QgsMeshLayer:: triangularMesh() const
Returns triangular mesh (nullptr before rendering)
void QgsMeshLayer:: activeScalarDatasetChanged(const QgsMeshDatasetIndex& index) signal
Emitted when active scalar dataset is changed.
void QgsMeshLayer:: activeVectorDatasetChanged(const QgsMeshDatasetIndex& index) signal
Emitted when active vector dataset is changed.