QGIS API Documentation  3.17.0-Master (a035f434f4)
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  QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
356 
367  int datasetCount( const QgsMeshDatasetIndex &index ) const;
368 
379  QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
380 
398  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
399 
418  QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
419 
436  QgsMesh3dDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
437 
445  bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
446 
459  QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
460 
483  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
484 
504  QgsMesh3dDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
505 
525  QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
526 
542  QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
543 
559  QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
560 
572  QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
573 
585  QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
586 
594  void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
595 
603  void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
604 
610  QgsMeshDatasetIndex staticScalarDatasetIndex() const;
611 
617  QgsMeshDatasetIndex staticVectorDatasetIndex() const;
618 
626  void setReferenceTime( const QDateTime &referenceTime );
627 
635  void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
636 
658  QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
659 
667  QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
668 
682  void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
683 
689  void resetDatasetGroupTreeItem();
690 
696  QgsInterval firstValidTimeStep() const;
697 
703  QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
704 
710  qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
711 
712  public slots:
713 
719  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
720 
721  signals:
722 
728  void activeScalarDatasetGroupChanged( int index );
729 
735  void activeVectorDatasetGroupChanged( int index );
736 
742  void timeSettingsChanged( );
743 
744  private: // Private methods
745 
749  bool isReadOnly() const override {return true;}
750 
757  bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
758 
759 #ifdef SIP_RUN
760  QgsMeshLayer( const QgsMeshLayer &rhs );
761 #endif
762 
763  void fillNativeMesh();
764  void assignDefaultStyleToDatasetGroup( int groupIndex );
765  void setDefaultRendererSettings( const QList<int> &groupIndexes );
766  void createSimplifiedMeshes();
767  int levelsOfDetailsIndex( double partOfMeshInView ) const;
768 
769  bool hasSimplifiedMeshes() const;
770 
772  void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
773 
774  private slots:
775  void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
776 
777  private:
779  QgsMeshDataProvider *mDataProvider = nullptr;
780 
781  std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
782 
784  std::unique_ptr<QgsMesh> mNativeMesh;
785 
787  std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
788 
790  std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
791 
793  QgsMeshRendererSettings mRendererSettings;
794 
796  QgsMeshTimeSettings mTimeSettings;
797 
799  QgsMeshSimplificationSettings mSimplificationSettings;
800 
801  QgsMeshLayerTemporalProperties *mTemporalProperties;
802 
803  int mStaticScalarDatasetIndex = 0;
804  int mStaticVectorDatasetIndex = 0;
805 
806  int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
807 
809  QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
810 
812  QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
813 
815  QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
816 
817  void updateActiveDatasetGroups();
818 };
819 
820 #endif //QGSMESHLAYER_H
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:41
Base class for all map layer types.
Definition: qgsmaplayer.h:83
Triangular/Derived Mesh is mesh with vertices in map coordinates.
QgsCoordinateTransformContext transformContext
Definition: qgsmeshlayer.h:113
Class for handling properties relating to a mesh data provider&#39;s temporal capabilities.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
A class to represent a 2D point.
Definition: qgspointxy.h:43
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e...
Represents a mesh renderer settings for scalar datasets.
QgsMesh3dDataBlock is a block of 3d stacked mesh data related N faces defined on base mesh frame...
Implementation of map layer temporal properties for mesh layers.
Setting options for loading mesh layers.
Definition: qgsmeshlayer.h:102
Tree item for display of the mesh dataset groups.
Represents all mesh renderer settings.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
Contains information about the context in which a coordinate transform is executed.
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Definition: qgsmeshlayer.h:109
Represents a mesh time settings for mesh datasets.
Class used to register and access all the dataset groups related to a mesh layer. ...
A representation of the interval between two datetime values.
Definition: qgsinterval.h:40
Base class for providing data for QgsMeshLayer.
Base class for storage of map layer temporal properties.
Contains information about the context of a rendering operation.
Setting options for creating vector data providers.
Represents a overview renderer settings.
Mesh - vertices, edges and faces.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Abstract class to interpolate 3d stacked mesh data to 2d data.
Class for doing transforms between two map coordinate systems.
Base class for utility classes that encapsulate information necessary for rendering of map layers...
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:94
QgsMeshDatasetValue represents single dataset value.
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
Abstract class that represents a dataset group.