QGIS API Documentation  3.21.0-Master (5b68dc587e)
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"
31 
33 struct QgsMeshLayerRendererCache;
34 class QgsSymbol;
35 class QgsTriangularMesh;
36 class QgsRenderContext;
37 struct QgsMesh;
41 class QgsMeshEditor;
42 
96 class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
97 {
98  Q_OBJECT
99  public:
100 
105  {
106 
112  : transformContext( transformContext )
113  {}
114 
116 
130  bool skipCrsValidation = false;
131  };
132 
146  explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = QStringLiteral( "mesh_memory" ),
148 
149  ~QgsMeshLayer() override;
150 
152  QgsMeshLayer( const QgsMeshLayer &rhs ) = delete;
154  QgsMeshLayer &operator=( QgsMeshLayer const &rhs ) = delete;
155 
156 #ifdef SIP_RUN
157  SIP_PYOBJECT __repr__();
158  % MethodCode
159  QString str = QStringLiteral( "<QgsMeshLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
160  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
161  % End
162 #endif
163 
164  QgsMeshDataProvider *dataProvider() override;
165  const QgsMeshDataProvider *dataProvider() const override SIP_SKIP;
166  QgsMeshLayer *clone() const override SIP_FACTORY;
167  QgsRectangle extent() const override;
168  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
169  bool readSymbology( const QDomNode &node, QString &errorMessage,
170  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
171  bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
172  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
173  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const override;
174  bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
175  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
176  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
177  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
178  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
179  QgsMapLayerTemporalProperties *temporalProperties() override;
180  void reload() override;
181  QStringList subLayers() const override;
182  QString htmlMetadata() const override;
183  bool isEditable() const override;
184  bool supportsEditing() const override;
185 
187  QString providerType() const;
188 
198  bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );
199 
208  bool addDatasets( QgsMeshDatasetGroup *datasetGroup SIP_TRANSFER );
209 
220  bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
221 
227  QgsMesh *nativeMesh() SIP_SKIP;
228 
234  const QgsMesh *nativeMesh() const SIP_SKIP;
235 
248  QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
249 
256  int triangularMeshLevelOfDetailCount() const SIP_SKIP;
257 
268  QgsTriangularMesh *triangularMeshByLodIndex( int lodIndex ) const SIP_SKIP;
269 
277  void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
278 
284  QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
285 
287  QgsMeshRendererSettings rendererSettings() const;
289  void setRendererSettings( const QgsMeshRendererSettings &settings );
290 
296  QgsMeshTimeSettings timeSettings() const;
297 
303  void setTimeSettings( const QgsMeshTimeSettings &settings );
304 
310  QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
311 
317  void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
318 
325  QString formatTime( double hours );
326 
332  int datasetGroupCount() const;
333 
339  int extraDatasetGroupCount() const;
340 
349  QList<int> datasetGroupsIndexes() const;
350 
359  QList<int> enabledDatasetGroupsIndexes() const;
360 
369  QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
370 
381  int datasetCount( const QgsMeshDatasetIndex &index ) const;
382 
393  QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
394 
412  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
413 
432  QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
433 
450  QgsMesh3dDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
451 
459  bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
460 
473  QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
474 
497  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
498 
518  QgsMesh3dDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
519 
539  QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
540 
556  QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
557 
573  QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
574 
586  QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
587 
599  QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
600 
608  void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
609 
617  void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
618 
624  QgsMeshDatasetIndex staticScalarDatasetIndex() const;
625 
631  QgsMeshDatasetIndex staticVectorDatasetIndex() const;
632 
640  void setReferenceTime( const QDateTime &referenceTime );
641 
649  void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
650 
672  QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
673 
682  QList<int> selectVerticesByExpression( QgsExpression expression );
683 
692  QList<int> selectFacesByExpression( QgsExpression expression );
693 
701  QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
702 
716  void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
717 
723  void resetDatasetGroupTreeItem();
724 
730  QgsInterval firstValidTimeStep() const;
731 
737  QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
738 
744  qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
745 
752  bool startFrameEditing( const QgsCoordinateTransform &transform );
753 
762  bool commitFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
763 
772  bool rollBackFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
773 
781  void stopFrameEditing( const QgsCoordinateTransform &transform );
782 
792  bool reindex( const QgsCoordinateTransform &transform, bool renumber );
793 
799  QgsMeshEditor *meshEditor();
800 
806  bool isModified() const override;
807 
812  bool contains( const QgsMesh::ElementType &type ) const;
813 
821  int meshVertexCount() const;
822 
830  int meshFaceCount() const;
831 
837  int meshEdgeCount() const;
838 
839  public slots:
840 
846  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
847 
848  signals:
849 
855  void activeScalarDatasetGroupChanged( int index );
856 
862  void activeVectorDatasetGroupChanged( int index );
863 
869  void timeSettingsChanged( );
870 
871  private: // Private methods
872 
876  bool isReadOnly() const override {return true;}
877 
884  bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
885 
886 #ifdef SIP_RUN
887  QgsMeshLayer( const QgsMeshLayer &rhs );
888 #endif
889 
890  void fillNativeMesh();
891  void assignDefaultStyleToDatasetGroup( int groupIndex );
892  void setDefaultRendererSettings( const QList<int> &groupIndexes );
893  void createSimplifiedMeshes();
894  int levelsOfDetailsIndex( double partOfMeshInView ) const;
895 
896  bool hasSimplifiedMeshes() const;
897 
899  void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
900 
901  private slots:
902  void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
903  void onMeshEdited();
904 
905  private:
907  QgsMeshDataProvider *mDataProvider = nullptr;
908 
910  QStringList mExtraDatasetUri;
911 
912  std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
913 
915  std::unique_ptr<QgsMesh> mNativeMesh;
916 
918  std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
919 
921  std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
922 
924  QgsMeshRendererSettings mRendererSettings;
925 
927  QgsMeshTimeSettings mTimeSettings;
928 
930  QgsMeshSimplificationSettings mSimplificationSettings;
931 
932  QgsMeshLayerTemporalProperties *mTemporalProperties = nullptr;
933 
936 
937  int mStaticScalarDatasetIndex = 0;
938  int mStaticVectorDatasetIndex = 0;
939 
940  QgsMeshEditor *mMeshEditor = nullptr;
941 
942  int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
943 
945  QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
946 
948  QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
949 
951  QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
952 
953  void updateActiveDatasetGroups();
954 
955  void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
956  const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags ) override;
957 };
958 
959 #endif //QGSMESHLAYER_H
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 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:65
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:97
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
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:38
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 SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
Setting options for creating vector data providers.
Setting options for loading mesh layers.
Definition: qgsmeshlayer.h:105
QgsCoordinateTransformContext transformContext
Definition: qgsmeshlayer.h:115
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Definition: qgsmeshlayer.h:111
Mesh - vertices, edges and faces.