QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 #ifdef SIP_RUN
155  SIP_PYOBJECT __repr__();
156  % MethodCode
157  QString str = QStringLiteral( "<QgsMeshLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
158  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
159  % End
160 #endif
161 
162  QgsMeshDataProvider *dataProvider() override;
163  const QgsMeshDataProvider *dataProvider() const override SIP_SKIP;
164  QgsMeshLayer *clone() const override SIP_FACTORY;
165  QgsRectangle extent() const override;
166  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
167  bool readSymbology( const QDomNode &node, QString &errorMessage,
168  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
169  bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
170  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
171  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const override;
172  bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
173  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
174  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
175  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
176  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
177  QgsMapLayerTemporalProperties *temporalProperties() override;
178  void reload() override;
179  QStringList subLayers() const override;
180  QString htmlMetadata() const override;
181 
183  QString providerType() const;
184 
194  bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );
195 
204  bool addDatasets( QgsMeshDatasetGroup *datasetGroup SIP_TRANSFER );
205 
216  bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
217 
223  QgsMesh *nativeMesh() SIP_SKIP;
224 
230  const QgsMesh *nativeMesh() const SIP_SKIP;
231 
244  QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
245 
252  int triangularMeshLevelOfDetailCount() const SIP_SKIP;
253 
264  QgsTriangularMesh *triangularMeshByLodIndex( int lodIndex ) const SIP_SKIP;
265 
273  void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
274 
280  QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
281 
283  QgsMeshRendererSettings rendererSettings() const;
285  void setRendererSettings( const QgsMeshRendererSettings &settings );
286 
292  QgsMeshTimeSettings timeSettings() const;
293 
299  void setTimeSettings( const QgsMeshTimeSettings &settings );
300 
306  QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
307 
313  void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
314 
321  QString formatTime( double hours );
322 
328  int datasetGroupCount() const;
329 
335  int extraDatasetGroupCount() const;
336 
345  QList<int> datasetGroupsIndexes() const;
346 
355  QList<int> enabledDatasetGroupsIndexes() const;
356 
365  QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
366 
377  int datasetCount( const QgsMeshDatasetIndex &index ) const;
378 
389  QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
390 
408  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
409 
428  QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
429 
446  QgsMesh3dDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
447 
455  bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
456 
469  QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
470 
493  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
494 
514  QgsMesh3dDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
515 
535  QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
536 
552  QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
553 
569  QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
570 
582  QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
583 
595  QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
596 
604  void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
605 
613  void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
614 
620  QgsMeshDatasetIndex staticScalarDatasetIndex() const;
621 
627  QgsMeshDatasetIndex staticVectorDatasetIndex() const;
628 
636  void setReferenceTime( const QDateTime &referenceTime );
637 
645  void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
646 
668  QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
669 
677  QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
678 
692  void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
693 
699  void resetDatasetGroupTreeItem();
700 
706  QgsInterval firstValidTimeStep() const;
707 
713  QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
714 
720  qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
721 
722  public slots:
723 
729  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
730 
731  signals:
732 
738  void activeScalarDatasetGroupChanged( int index );
739 
745  void activeVectorDatasetGroupChanged( int index );
746 
752  void timeSettingsChanged( );
753 
754  private: // Private methods
755 
759  bool isReadOnly() const override {return true;}
760 
767  bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
768 
769 #ifdef SIP_RUN
770  QgsMeshLayer( const QgsMeshLayer &rhs );
771 #endif
772 
773  void fillNativeMesh();
774  void assignDefaultStyleToDatasetGroup( int groupIndex );
775  void setDefaultRendererSettings( const QList<int> &groupIndexes );
776  void createSimplifiedMeshes();
777  int levelsOfDetailsIndex( double partOfMeshInView ) const;
778 
779  bool hasSimplifiedMeshes() const;
780 
782  void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
783 
784  private slots:
785  void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
786 
787  private:
789  QgsMeshDataProvider *mDataProvider = nullptr;
790 
792  QStringList mExtraDatasetUri;
793 
794  std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
795 
797  std::unique_ptr<QgsMesh> mNativeMesh;
798 
800  std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
801 
803  std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
804 
806  QgsMeshRendererSettings mRendererSettings;
807 
809  QgsMeshTimeSettings mTimeSettings;
810 
812  QgsMeshSimplificationSettings mSimplificationSettings;
813 
814  QgsMeshLayerTemporalProperties *mTemporalProperties = nullptr;
815 
818 
819  int mStaticScalarDatasetIndex = 0;
820  int mStaticVectorDatasetIndex = 0;
821 
822  int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
823 
825  QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
826 
828  QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
829 
831  QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
832 
833  void updateActiveDatasetGroups();
834 
835  void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
836  const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags ) override;
837 };
838 
839 #endif //QGSMESHLAYER_H
Contains information about the context in which a coordinate transform is executed.
Class for doing transforms between two map coordinate systems.
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:70
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.
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:95
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 a 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:103
QgsCoordinateTransformContext transformContext
Definition: qgsmeshlayer.h:113
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Definition: qgsmeshlayer.h:109
Mesh - vertices, edges and faces.