QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
32 struct QgsMeshLayerRendererCache;
33 class QgsSymbol;
34 class QgsTriangularMesh;
35 class QgsRenderContext;
36 struct QgsMesh;
40 
94 class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
95 {
96  Q_OBJECT
97  public:
98 
103  {
104 
110  : transformContext( transformContext )
111  {}
112 
114 
128  bool skipCrsValidation = false;
129  };
130 
144  explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = QStringLiteral( "mesh_memory" ),
146 
147  ~QgsMeshLayer() override;
148 
150  QgsMeshLayer( const QgsMeshLayer &rhs ) = delete;
152  QgsMeshLayer &operator=( QgsMeshLayer const &rhs ) = delete;
153 
154  QgsMeshDataProvider *dataProvider() override;
155  const QgsMeshDataProvider *dataProvider() const override SIP_SKIP;
156  QgsMeshLayer *clone() const override SIP_FACTORY;
157  QgsRectangle extent() const override;
158  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
159  bool readSymbology( const QDomNode &node, QString &errorMessage,
160  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
161  bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
162  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
163  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const override;
164  bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
165  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
166  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
167  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
168  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
169  QgsMapLayerTemporalProperties *temporalProperties() override;
170  void reload() override;
171  QStringList subLayers() const override;
172  QString htmlMetadata() const override;
173 
175  QString providerType() const;
176 
186  bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );
187 
196  bool addDatasets( QgsMeshDatasetGroup *datasetGroup SIP_TRANSFER );
197 
208  bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
209 
215  QgsMesh *nativeMesh() SIP_SKIP;
216 
222  const QgsMesh *nativeMesh() const SIP_SKIP;
223 
236  QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
237 
245  void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
246 
252  QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
253 
255  QgsMeshRendererSettings rendererSettings() const;
257  void setRendererSettings( const QgsMeshRendererSettings &settings );
258 
264  QgsMeshTimeSettings timeSettings() const;
265 
271  void setTimeSettings( const QgsMeshTimeSettings &settings );
272 
278  QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
279 
285  void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
286 
293  QString formatTime( double hours );
294 
300  int datasetGroupCount() const;
301 
307  int extraDatasetGroupCount() const;
308 
317  QList<int> datasetGroupsIndexes() const;
318 
327  QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
328 
339  int datasetCount( const QgsMeshDatasetIndex &index ) const;
340 
351  QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
352 
370  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
371 
390  QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
391 
408  QgsMesh3dDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
409 
417  bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
418 
431  QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
432 
455  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
456 
476  QgsMesh3dDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
477 
497  QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
498 
513  QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
514 
529  QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
530 
542  QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
543 
555  QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
556 
564  void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
565 
573  void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
574 
580  QgsMeshDatasetIndex staticScalarDatasetIndex() const;
581 
587  QgsMeshDatasetIndex staticVectorDatasetIndex() const;
588 
596  void setReferenceTime( const QDateTime &referenceTime );
597 
605  void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
606 
628  QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
629 
637  QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
638 
652  void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
653 
659  void resetDatasetGroupTreeItem();
660 
666  QgsInterval firstValidTimeStep() const;
667 
673  QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
674 
680  qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
681 
682  public slots:
683 
689  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
690 
691  signals:
692 
698  void activeScalarDatasetGroupChanged( int index );
699 
705  void activeVectorDatasetGroupChanged( int index );
706 
712  void timeSettingsChanged( );
713 
714  private: // Private methods
715 
719  bool isReadOnly() const override {return true;}
720 
727  bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
728 
729 #ifdef SIP_RUN
730  QgsMeshLayer( const QgsMeshLayer &rhs );
731 #endif
732 
733  void fillNativeMesh();
734  void assignDefaultStyleToDatasetGroup( int groupIndex );
735  void setDefaultRendererSettings( const QList<int> &groupIndexes );
736  void createSimplifiedMeshes();
737  int levelsOfDetailsIndex( double partOfMeshInView ) const;
738 
739  bool hasSimplifiedMeshes() const;
740 
742  void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
743 
744  private slots:
745  void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
746 
747  private:
749  QgsMeshDataProvider *mDataProvider = nullptr;
750 
751  std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
752 
754  std::unique_ptr<QgsMesh> mNativeMesh;
755 
757  std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
758 
760  std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
761 
763  QgsMeshRendererSettings mRendererSettings;
764 
766  QgsMeshTimeSettings mTimeSettings;
767 
769  QgsMeshSimplificationSettings mSimplificationSettings;
770 
771  QgsMeshLayerTemporalProperties *mTemporalProperties;
772 
773  int mStaticScalarDatasetIndex = 0;
774  int mStaticVectorDatasetIndex = 0;
775 
776  int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
777 
779  QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
780 
782  QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
783 
785  QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
786 
787  void updateActiveDatasetGroups();
788 };
789 
790 #endif //QGSMESHLAYER_H
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsMeshTimeSettings
Represents a mesh time settings for mesh datasets.
Definition: qgsmeshtimesettings.h:36
QgsMeshRendererSettings
Represents all mesh renderer settings.
Definition: qgsmeshrenderersettings.h:591
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:105
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsMeshDataProviderTemporalCapabilities
Class for handling properties relating to a mesh data provider's temporal capabilities.
Definition: qgsmeshdataprovidertemporalcapabilities.h:35
qgsinterval.h
QgsMeshLayer::LayerOptions::transformContext
QgsCoordinateTransformContext transformContext
Definition: qgsmeshlayer.h:113
qgsmeshsimplificationsettings.h
QgsMeshDatasetValue
QgsMeshDatasetValue represents single dataset value.
Definition: qgsmeshdataset.h:78
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsMeshLayerTemporalProperties
Implementation of map layer temporal properties for mesh layers.
Definition: qgsmeshlayertemporalproperties.h:52
QgsMeshDatasetGroupTreeItem
Tree item for display of the mesh dataset groups.
Definition: qgsmeshdataset.h:785
QgsMesh
Mesh - vertices, edges and faces.
Definition: qgsmeshdataprovider.h:58
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsMeshDatasetMetadata
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
Definition: qgsmeshdataset.h:476
QgsMesh3dDataBlock
QgsMesh3dDataBlock is a block of 3d stacked mesh data related N faces defined on base mesh frame.
Definition: qgsmeshdataset.h:245
QgsMeshLayer::LayerOptions
Setting options for loading mesh layers.
Definition: qgsmeshlayer.h:103
QgsMapLayerRenderer
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Definition: qgsmaplayerrenderer.h:51
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMeshDatasetGroupStore
Class used to register and access all the dataset groups related to a mesh layer.
Definition: qgsmeshdatasetgroupstore.h:120
qgsmeshtimesettings.h
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsMeshDatasetIndex
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Definition: qgsmeshdataset.h:47
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:95
qgsmaplayer.h
QgsMeshLayer::LayerOptions::LayerOptions
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Definition: qgsmeshlayer.h:109
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMeshDataProvider
Base class for providing data for QgsMeshLayer.
Definition: qgsmeshdataprovider.h:398
QgsMapLayerTemporalProperties
Base class for storage of map layer temporal properties.
Definition: qgsmaplayertemporalproperties.h:43
QgsMesh3dAveragingMethod
Abstract class to interpolate 3d stacked mesh data to 2d data.
Definition: qgsmesh3daveraging.h:40
QgsMeshDatasetGroup
Abstract class that represents a dataset group.
Definition: qgsmeshdataset.h:576
QgsMeshSimplificationSettings
Represents a overview renderer settings.
Definition: qgsmeshsimplificationsettings.h:40
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
qgsmeshrenderersettings.h
QgsMeshRendererScalarSettings
Represents a mesh renderer settings for scalar datasets.
Definition: qgsmeshrenderersettings.h:95
QgsMeshDatasetGroupMetadata
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
Definition: qgsmeshdataset.h:350
QgsMeshLayer::operator=
QgsMeshLayer & operator=(QgsMeshLayer const &rhs)=delete
QgsMeshLayer cannot be copied.
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsInterval
A representation of the interval between two datetime values.
Definition: qgsinterval.h:41
QgsMeshDataBlock
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
Definition: qgsmeshdataset.h:136
QgsMeshLayer::QgsMeshLayer
QgsMeshLayer(const QgsMeshLayer &rhs)=delete
QgsMeshLayer cannot be copied.
QgsTriangularMesh
Triangular/Derived Mesh is mesh with vertices in map coordinates.
Definition: qgstriangularmesh.h:50
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:53
qgsmeshdataprovider.h
QgsMapLayer::dataProvider
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Definition: qgsmaplayer.cpp:169