QGIS API Documentation  3.27.0-Master (e113457133)
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"
24 #include "qgsinterval.h"
25 #include "qgsmaplayer.h"
26 #include "qgsmeshdataprovider.h"
28 #include "qgsmeshtimesettings.h"
30 #include "qgscoordinatetransform.h"
32 
34 struct QgsMeshLayerRendererCache;
35 class QgsSymbol;
36 class QgsTriangularMesh;
37 class QgsRenderContext;
38 struct QgsMesh;
42 class QgsMeshEditor;
44 
98 class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSource
99 {
100  Q_OBJECT
101  public:
102 
107  {
108 
114  : transformContext( transformContext )
115  {}
116 
121 
126  bool loadDefaultStyle = true;
127 
141  bool skipCrsValidation = false;
142  };
143 
157  explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = QStringLiteral( "mesh_memory" ),
159 
160  ~QgsMeshLayer() override;
161 
163  QgsMeshLayer( const QgsMeshLayer &rhs ) = delete;
165  QgsMeshLayer &operator=( QgsMeshLayer const &rhs ) = delete;
166 
167 #ifdef SIP_RUN
168  SIP_PYOBJECT __repr__();
169  % MethodCode
170  QString str = QStringLiteral( "<QgsMeshLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
171  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
172  % End
173 #endif
174 
175  QgsMeshDataProvider *dataProvider() override;
176  const QgsMeshDataProvider *dataProvider() const override SIP_SKIP;
177  QgsMeshLayer *clone() const override SIP_FACTORY;
178  QgsRectangle extent() const override;
179  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
180  QgsAbstractProfileGenerator *createProfileGenerator( const QgsProfileRequest &request ) override SIP_FACTORY;
181  bool readSymbology( const QDomNode &node, QString &errorMessage,
182  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
183  bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
184  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
185  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const override;
186  bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
187  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
188  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
189  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
190  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
191  QgsMapLayerTemporalProperties *temporalProperties() override;
192  QgsMapLayerElevationProperties *elevationProperties() override;
193  void reload() override;
194  QStringList subLayers() const override;
195  QString htmlMetadata() const override;
196  bool isEditable() const override;
197  bool supportsEditing() const override;
198  QString loadDefaultStyle( bool &resultFlag SIP_OUT ) FINAL;
199 
201  QString providerType() const;
202 
212  bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );
213 
222  bool addDatasets( QgsMeshDatasetGroup *datasetGroup SIP_TRANSFER );
223 
234  bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
235 
241  QgsMesh *nativeMesh() SIP_SKIP;
242 
248  const QgsMesh *nativeMesh() const SIP_SKIP;
249 
262  QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
263 
270  int triangularMeshLevelOfDetailCount() const SIP_SKIP;
271 
282  QgsTriangularMesh *triangularMeshByLodIndex( int lodIndex ) const SIP_SKIP;
283 
291  void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
292 
298  QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
299 
301  QgsMeshRendererSettings rendererSettings() const;
303  void setRendererSettings( const QgsMeshRendererSettings &settings );
304 
310  QgsMeshTimeSettings timeSettings() const;
311 
317  void setTimeSettings( const QgsMeshTimeSettings &settings );
318 
324  QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
325 
331  void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
332 
339  QString formatTime( double hours );
340 
346  int datasetGroupCount() const;
347 
353  int extraDatasetGroupCount() const;
354 
363  QList<int> datasetGroupsIndexes() const;
364 
373  QList<int> enabledDatasetGroupsIndexes() const;
374 
383  QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
384 
395  int datasetCount( const QgsMeshDatasetIndex &index ) const;
396 
407  QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
408 
426  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
427 
446  QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
447 
464  QgsMesh3dDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
465 
473  bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
474 
487  QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
488 
511  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
512 
532  QgsMesh3dDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
533 
553  QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
554 
570  QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
571 
587  QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
588 
603  QList<QgsMeshDatasetIndex> datasetIndexInRelativeTimeInterval( const QgsInterval &startRelativeTime, const QgsInterval &endRelativeTime, int datasetGroupIndex ) const;
604 
616  QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
617 
629  QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
630 
638  void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
639 
647  void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
648 
654  QgsMeshDatasetIndex staticScalarDatasetIndex() const;
655 
661  QgsMeshDatasetIndex staticVectorDatasetIndex() const;
662 
670  void setReferenceTime( const QDateTime &referenceTime );
671 
679  void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
680 
702  QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
703 
712  QList<int> selectVerticesByExpression( QgsExpression expression );
713 
722  QList<int> selectFacesByExpression( QgsExpression expression );
723 
731  QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
732 
746  void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
747 
753  void resetDatasetGroupTreeItem();
754 
760  QgsInterval firstValidTimeStep() const;
761 
767  QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
768 
774  qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
775 
782  bool startFrameEditing( const QgsCoordinateTransform &transform );
783 
792  bool commitFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
793 
802  bool rollBackFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
803 
811  void stopFrameEditing( const QgsCoordinateTransform &transform );
812 
822  bool reindex( const QgsCoordinateTransform &transform, bool renumber );
823 
829  QgsMeshEditor *meshEditor();
830 
836  bool isModified() const override;
837 
842  bool contains( const QgsMesh::ElementType &type ) const;
843 
851  int meshVertexCount() const;
852 
860  int meshFaceCount() const;
861 
867  int meshEdgeCount() const;
868 
869  public slots:
870 
876  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
877 
878  signals:
879 
885  void activeScalarDatasetGroupChanged( int index );
886 
892  void activeVectorDatasetGroupChanged( int index );
893 
899  void timeSettingsChanged( );
900 
901  private: // Private methods
902 
906  bool isReadOnly() const override {return true;}
907 
914  bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
915 
916 #ifdef SIP_RUN
917  QgsMeshLayer( const QgsMeshLayer &rhs );
918 #endif
919 
920  void fillNativeMesh();
921  void assignDefaultStyleToDatasetGroup( int groupIndex );
922  void createSimplifiedMeshes();
923  int levelsOfDetailsIndex( double partOfMeshInView ) const;
924 
925  bool hasSimplifiedMeshes() const;
926 
928  void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
929 
930  private slots:
931  void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
932  void onMeshEdited();
933 
934  private:
936  QgsMeshDataProvider *mDataProvider = nullptr;
937 
939  QStringList mExtraDatasetUri;
940 
941  std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
942 
944  std::unique_ptr<QgsMesh> mNativeMesh;
945 
947  std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
948 
950  std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
951 
953  QgsMeshRendererSettings mRendererSettings;
954 
956  QgsMeshTimeSettings mTimeSettings;
957 
959  QgsMeshSimplificationSettings mSimplificationSettings;
960 
961  QgsMeshLayerTemporalProperties *mTemporalProperties = nullptr;
962  QgsMeshLayerElevationProperties *mElevationProperties = nullptr;
963 
966 
967  int mStaticScalarDatasetIndex = 0;
968  int mStaticVectorDatasetIndex = 0;
969 
970  QgsMeshEditor *mMeshEditor = nullptr;
971 
972  int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
973 
975  QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
976 
978  QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
979 
981  QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
982 
983  void updateActiveDatasetGroups();
984 
985  void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
986  const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags ) override;
987 };
988 
989 #endif //QGSMESHLAYER_H
Abstract base class for objects which generate elevation profiles.
Interface for classes which can generate elevation profiles.
Contains information about the context in which a coordinate transform is executed.
Class for doing transforms between two map coordinate systems.
Class for parsing and evaluation of expressions (formerly called "search strings").
A representation of the interval between two datetime values.
Definition: qgsinterval.h:42
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.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Abstract class to interpolate 3d stacked mesh data to 2d data.
QgsMesh3dDataBlock is a block of 3d stacked mesh data related N faces defined on base mesh frame.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
Class for handling properties relating to a mesh data provider's temporal capabilities.
Base class for providing data for QgsMeshLayer.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
Class used to register and access 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.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
QgsMeshDatasetValue represents single dataset value.
Class that makes edit operation on a mesh.
Definition: qgsmesheditor.h:68
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.
Definition: qgsmeshlayer.h:99
QgsMeshLayer(const QgsMeshLayer &rhs)=delete
QgsMeshLayer cannot be copied.
QgsMeshLayer & operator=(QgsMeshLayer const &rhs)=delete
QgsMeshLayer cannot be copied.
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.
A class to represent a 2D point.
Definition: qgspointxy.h:59
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
Triangular/Derived Mesh is mesh with vertices in map coordinates.
TemporalUnit
Temporal units.
Definition: qgsunittypes.h:150
@ TemporalHours
Hours.
Definition: qgsunittypes.h:154
#define str(x)
Definition: qgis.cpp:37
#define SIP_SKIP
Definition: qgis_sip.h:126
#define FINAL
Definition: qgis_sip.h:237
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
Setting options for creating vector data providers.
Setting options for loading mesh layers.
Definition: qgsmeshlayer.h:107
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsmeshlayer.h:120
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Definition: qgsmeshlayer.h:113
Mesh - vertices, edges and faces.