QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsmeshlayer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshlayer.h
3 --------------
4 begin : April 2018
5 copyright : (C) 2018 by Peter Petrik
6 email : zilolv at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSMESHLAYER_H
19#define QGSMESHLAYER_H
20
21#include <memory>
22
23#include "qgis_core.h"
26#include "qgsinterval.h"
27#include "qgsmaplayer.h"
28#include "qgsmeshdataprovider.h"
31#include "qgsmeshtimesettings.h"
32
33#include <QString>
34
35using namespace Qt::StringLiterals;
36
38struct QgsMeshLayerRendererCache;
39class QgsSymbol;
42struct QgsMesh;
46class QgsMeshEditor;
50
104class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSource
105{
106 Q_OBJECT
107 public:
108
149
163 explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = u"mesh_memory"_s,
165
166 ~QgsMeshLayer() override;
167
168 QgsMeshLayer( const QgsMeshLayer &rhs ) = delete;
169 QgsMeshLayer &operator=( QgsMeshLayer const &rhs ) = delete;
170
171#ifdef SIP_RUN
172 SIP_PYOBJECT __repr__();
173 % MethodCode
174 QString str = u"<QgsMeshLayer: '%1' (%2)>"_s.arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : u"Invalid"_s );
175 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
176 % End
177#endif
178
180 const QgsMeshDataProvider *dataProvider() const override SIP_SKIP;
181 QgsMeshLayer *clone() const override SIP_FACTORY;
182 QgsRectangle extent() const override;
184 QgsAbstractProfileSource *profileSource() override {return this;}
185 QString profileSourceId() const override {return id();}
186 QString profileSourceName() const override {return name();}
188 bool readSymbology( const QDomNode &node, QString &errorMessage,
190 bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
191 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
192 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const override;
193 bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
194 QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
195 QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
196 bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
197 bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
200 void reload() override;
201 QStringList subLayers() const override;
202 QString htmlMetadata() const override;
203 bool isEditable() const override;
204 bool supportsEditing() const override;
205 QString loadDefaultStyle( bool &resultFlag SIP_OUT ) final;
206
216 bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );
217
226 bool removeDatasets( const QString &name );
227
236 bool addDatasets( QgsMeshDatasetGroup *datasetGroup SIP_TRANSFER );
237
248 bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
249
255 QgsMesh *nativeMesh() SIP_SKIP;
256
262 const QgsMesh *nativeMesh() const SIP_SKIP;
263
276 QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
277
284 int triangularMeshLevelOfDetailCount() const SIP_SKIP;
285
296 QgsTriangularMesh *triangularMeshByLodIndex( int lodIndex ) const SIP_SKIP;
297
305 void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
306
312 QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
313
315 QgsMeshRendererSettings rendererSettings() const;
316
323 void setRendererSettings( const QgsMeshRendererSettings &settings, const bool repaint = true );
324
330 QgsMeshTimeSettings timeSettings() const;
331
337 void setTimeSettings( const QgsMeshTimeSettings &settings );
338
344 QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
345
351 void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
352
359 QString formatTime( double hours );
360
366 int datasetGroupCount() const;
367
373 int extraDatasetGroupCount() const;
374
383 QList<int> datasetGroupsIndexes() const;
384
393 QList<int> enabledDatasetGroupsIndexes() const;
394
403 QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
404
415 int datasetCount( const QgsMeshDatasetIndex &index ) const;
416
427 QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
428
446 QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
447
466 QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
467
484 QgsMesh3DDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
485
493 bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
494
507 QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
508
531 QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
532
552 QgsMesh3DDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
553
573 QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
574
590 QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
591
607 QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
608
623 QList<QgsMeshDatasetIndex> datasetIndexInRelativeTimeInterval( const QgsInterval &startRelativeTime, const QgsInterval &endRelativeTime, int datasetGroupIndex ) const;
624
636 QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange, int group = -1 ) const;
637
649 QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange, int group = -1 ) const;
650
658 void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
659
667 void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
668
677 QgsMeshDatasetIndex staticScalarDatasetIndex( int group = -1 ) const;
678
687 QgsMeshDatasetIndex staticVectorDatasetIndex( int group = -1 ) const;
688
696 void setReferenceTime( const QDateTime &referenceTime );
697
705 void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
706
728 QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
729
756 int closestElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint SIP_OUT ) const;
757
766 QList<int> selectVerticesByExpression( QgsExpression expression );
767
776 QList<int> selectFacesByExpression( QgsExpression expression );
777
785 QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
786
800 void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
801
807 void resetDatasetGroupTreeItem();
808
814 QgsInterval firstValidTimeStep() const;
815
821 QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
822
828 qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
829
837 Q_DECL_DEPRECATED bool startFrameEditing( const QgsCoordinateTransform &transform );
838
849 bool startFrameEditing( const QgsCoordinateTransform &transform, QgsMeshEditingError &error SIP_OUT, bool fixErrors );
850
851
860 bool commitFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
861
870 bool rollBackFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
871
879 void stopFrameEditing( const QgsCoordinateTransform &transform );
880
890 bool reindex( const QgsCoordinateTransform &transform, bool renumber );
891
897 QgsMeshEditor *meshEditor();
898
904 bool isModified() const override;
905
910 bool contains( const QgsMesh::ElementType &type ) const;
911
919 int meshVertexCount() const;
920
928 int meshFaceCount() const;
929
935 int meshEdgeCount() const;
936
945 bool labelsEnabled() const;
946
957 void setLabelsEnabled( bool enabled );
958
967 const QgsAbstractMeshLayerLabeling *labeling() const SIP_SKIP { return mLabeling; }
968
975 QgsAbstractMeshLayerLabeling *labeling() { return mLabeling; }
976
981 void setLabeling( QgsAbstractMeshLayerLabeling *labeling SIP_TRANSFER );
982
992 bool minimumMaximumActiveScalarDataset( const QgsRectangle &extent, const QgsMeshDatasetIndex &datasetIndex, double &min SIP_OUT, double &max SIP_OUT );
993
999 QgsMeshDatasetIndex activeScalarDatasetIndex( QgsRenderContext &rendererContext );
1000
1010 bool datasetsPathUnique( const QString &path );
1011
1017 QStringList extraDatasetUris() const { return mExtraDatasetUri; }
1018
1019 public slots:
1020
1026 void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
1027
1028 signals:
1029
1036
1043
1050
1056 void reloaded();
1057
1058 private: // Private methods
1059
1063 bool isReadOnly() const override {return true;}
1064
1071 bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags = Qgis::DataProviderReadFlags() );
1072#ifdef SIP_RUN
1073 QgsMeshLayer( const QgsMeshLayer &rhs );
1074#endif
1075
1076 void fillNativeMesh();
1077 void assignDefaultStyleToDatasetGroup( int groupIndex );
1078 void createSimplifiedMeshes();
1079 int levelsOfDetailsIndex( double partOfMeshInView ) const;
1080
1081 bool hasSimplifiedMeshes() const;
1082
1084 void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
1085
1086 private slots:
1087 void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
1088 void onMeshEdited();
1089
1090 private:
1092 QgsMeshDataProvider *mDataProvider = nullptr;
1093
1095 QStringList mExtraDatasetUri;
1096
1097 std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
1098
1100 std::unique_ptr<QgsMesh> mNativeMesh;
1101
1103 std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
1104
1106 std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
1107
1109 QgsMeshRendererSettings mRendererSettings;
1110
1112 QgsMeshTimeSettings mTimeSettings;
1113
1115 QgsMeshSimplificationSettings mSimplificationSettings;
1116
1117 QgsMeshLayerTemporalProperties *mTemporalProperties = nullptr;
1118 QgsMeshLayerElevationProperties *mElevationProperties = nullptr;
1119
1122
1123 int mStaticScalarDatasetIndex = 0;
1124 int mStaticVectorDatasetIndex = 0;
1125
1126 QgsMeshEditor *mMeshEditor = nullptr;
1127
1129 bool mLabelsEnabled = false;
1130
1132 QgsAbstractMeshLayerLabeling *mLabeling = nullptr;
1133
1135 int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
1136
1138 int closestVertex( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
1139
1141 int closestFace( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
1142
1143 void updateActiveDatasetGroups();
1144
1145 QgsMeshRendererSettings accordSymbologyWithGroupName( const QgsMeshRendererSettings &settings, const QMap<QString, int> &nameToIndex );
1146 void checkSymbologyConsistency();
1147
1148 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
1150};
1151
1152#endif //QGSMESHLAYER_H
TemporalUnit
Temporal units.
Definition qgis.h:5231
@ Hours
Hours.
Definition qgis.h:5235
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:505
Abstract base class - its implementations define different approaches to the labeling of a mesh layer...
Abstract base class for objects which generate elevation profiles.
Interface for classes which can generate elevation profiles.
virtual QgsAbstractProfileGenerator * createProfileGenerator(const QgsProfileRequest &request)=0
Given a profile request, returns a new profile generator ready for generating elevation profiles.
Contains information about the context in which a coordinate transform is executed.
Handles coordinate transforms between two coordinate systems.
Handles parsing and evaluation of expressions (formerly called "search strings").
A representation of the interval between two datetime values.
Definition qgsinterval.h:50
Base class for storage of map layer elevation properties.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for storage of map layer temporal properties.
QString name
Definition qgsmaplayer.h:87
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the document provided.
virtual QString encodedSource(const QString &source, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
virtual bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files.
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by children to write state specific to them to project files.
QString id
Definition qgsmaplayer.h:86
QgsMapLayer(Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
virtual bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read the style for the current layer from the DOM node supplied.
virtual bool supportsEditing() const
Returns whether the layer supports editing or not.
QFlags< StyleCategory > StyleCategories
virtual bool isEditable() const
Returns true if the layer can be edited.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
virtual QStringList subLayers() const
Returns the sublayers of this layer.
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
Read the symbology for the current layer from the DOM node supplied.
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
virtual QString decodedSource(const QString &source, const QString &dataProvider, const QgsReadWriteContext &context) const
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
virtual bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write just the symbology information for the layer into the document.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
Abstract class for interpolating 3d stacked mesh data to 2d data.
A block of 3d stacked mesh data related N faces defined on base mesh frame.
A block of integers/doubles from a mesh dataset.
Handles properties relating to a mesh data provider's temporal capabilities.
Base class for providing data for QgsMeshLayer.
A collection of dataset group metadata such as whether the data is vector or scalar,...
Registers and accesses all the dataset groups related to a mesh layer.
Tree item for display of the mesh dataset groups.
Abstract class that represents a dataset group.
An index that identifies the dataset group (e.g.
Represents mesh dataset metadata, such as whether the data is valid or the associated time.
Represents a single mesh dataset value.
Represents an error which occurred during mesh editing.
Handles edit operations on a mesh layer.
Mesh layer specific subclass of QgsMapLayerElevationProperties.
Implementation of map layer temporal properties for mesh layers.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QString profileSourceName() const override
Returns a name for displaying this profile source in the elevation profile layer tree.
QgsRectangle extent() const override
Returns the extent of the layer.
QgsAbstractProfileSource * profileSource() override
Returns the layer's profile source if it has profile capabilities.
void activeScalarDatasetGroupChanged(int index)
Emitted when active scalar group dataset is changed.
void activeVectorDatasetGroupChanged(int index)
Emitted when active vector group dataset is changed.
const QgsAbstractMeshLayerLabeling * labeling() const
Access to const labeling configuration.
QgsMeshLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
void timeSettingsChanged()
Emitted when time format is changed.
QgsMeshLayer & operator=(QgsMeshLayer const &rhs)=delete
QStringList extraDatasetUris() const
Returns the list of extra dataset URIs associated with this layer.
QgsMeshLayer(const QgsMeshLayer &rhs)=delete
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
QString profileSourceId() const override
Returns a unique identifier for this profile source.
QgsMeshLayer(const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib=u"mesh_memory"_s, const QgsMeshLayer::LayerOptions &options=QgsMeshLayer::LayerOptions())
Constructor - creates a mesh layer.
QgsAbstractMeshLayerLabeling * labeling()
Access to labeling configuration.
void reloaded()
Emitted when the mesh layer is reloaded, see reload().
Represents a mesh renderer settings for scalar datasets.
Represents all mesh renderer settings.
Represents an overview renderer settings.
Represents a mesh time settings for mesh datasets.
Represents a 2D point.
Definition qgspointxy.h:62
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
A triangular/derived mesh with vertices in map coordinates.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:84
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:764
Setting options for creating vector data providers.
Setting options for loading mesh layers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Mesh - vertices, edges and faces.