QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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;
39 
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 
174  QString providerType() const;
175 
185  bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );
186 
192  QgsMesh *nativeMesh() SIP_SKIP;
193 
199  const QgsMesh *nativeMesh() const SIP_SKIP;
200 
213  QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
214 
222  void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
223 
229  QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
230 
232  QgsMeshRendererSettings rendererSettings() const;
234  void setRendererSettings( const QgsMeshRendererSettings &settings );
235 
241  QgsMeshTimeSettings timeSettings() const;
242 
248  void setTimeSettings( const QgsMeshTimeSettings &settings );
249 
255  QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
256 
262  void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
263 
270  QString formatTime( double hours );
271 
291  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
292 
309  QgsMesh3dDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
310 
327  QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
328 
329 
341  QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
342 
354  QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
355 
367  QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
368 
376  void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
377 
385  void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
386 
392  QgsMeshDatasetIndex staticScalarDatasetIndex() const;
393 
399  QgsMeshDatasetIndex staticVectorDatasetIndex() const;
400 
408  void setReferenceTime( const QDateTime &referenceTime );
409 
417  void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
418 
440  QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
441 
449  QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
450 
464  void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
465 
471  void resetDatasetGroupTreeItem();
472 
478  QgsInterval firstValidTimeStep() const;
479 
480  public slots:
481 
487  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
488 
489  signals:
490 
496  void activeScalarDatasetGroupChanged( int index );
497 
503  void activeVectorDatasetGroupChanged( int index );
504 
510  void timeSettingsChanged( );
511 
512  private: // Private methods
513 
517  bool isReadOnly() const override {return true;}
518 
524  bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options );
525 
526 #ifdef SIP_RUN
527  QgsMeshLayer( const QgsMeshLayer &rhs );
528 #endif
529 
530  private:
531  void fillNativeMesh();
532  void assignDefaultStyleToDatasetGroup( int groupIndex );
533  void setDefaultRendererSettings();
534  void createSimplifiedMeshes();
535  int levelsOfDetailsIndex( double partOfMeshInView ) const;
536 
537  bool hasSimplifiedMeshes() const;
538 
540  void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
541 
542  private slots:
543  void onDatasetGroupsAdded( int count );
544 
545  private:
547  QgsMeshDataProvider *mDataProvider = nullptr;
548 
550  std::unique_ptr<QgsMesh> mNativeMesh;
551 
553  std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
554 
556  std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
557 
559  QgsMeshRendererSettings mRendererSettings;
560 
562  QgsMeshTimeSettings mTimeSettings;
563 
565  QgsMeshSimplificationSettings mSimplificationSettings;
566 
567  QgsMeshLayerTemporalProperties *mTemporalProperties;
568 
569  int mStaticScalarDatasetIndex = 0;
570  int mStaticVectorDatasetIndex = 0;
571 
572  std::unique_ptr<QgsMeshDatasetGroupTreeItem> mDatasetGroupTreeRootItem;
573 
574  int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
575 
577  QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
578 
580  QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
581 
583  QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
584 
585  void updateActiveDatasetGroups();
586 };
587 
588 #endif //QGSMESHLAYER_H
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
QgsMeshTimeSettings
Definition: qgsmeshtimesettings.h:35
QgsMeshRendererSettings
Definition: qgsmeshrenderersettings.h:590
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:104
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsMeshDataProviderTemporalCapabilities
Definition: qgsmeshdataprovidertemporalcapabilities.h:33
qgsinterval.h
QgsMeshLayer::LayerOptions::transformContext
QgsCoordinateTransformContext transformContext
Definition: qgsmeshlayer.h:113
qgsmeshsimplificationsettings.h
QgsMeshDatasetValue
Definition: qgsmeshdataset.h:76
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsMeshLayerTemporalProperties
Definition: qgsmeshlayertemporalproperties.h:51
QgsMeshDatasetGroupTreeItem
Definition: qgsmeshdataset.h:546
QgsMesh
Definition: qgsmeshdataprovider.h:57
QgsSymbol
Definition: qgssymbol.h:63
QgsRectangle
Definition: qgsrectangle.h:41
QgsMesh3dDataBlock
Definition: qgsmeshdataset.h:243
QgsMeshLayer::LayerOptions
Setting options for loading mesh layers.
Definition: qgsmeshlayer.h:102
QgsMapLayerRenderer
Definition: qgsmaplayerrenderer.h:50
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
qgsmeshtimesettings.h
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsMapLayer::dataProvider
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Definition: qgsmaplayer.cpp:169
QgsMapLayer::operator=
QgsMapLayer & operator=(QgsMapLayer const &)=delete
QgsMapLayer cannot be copied.
QgsMeshDatasetIndex
Definition: qgsmeshdataset.h:45
QgsMeshLayer
Definition: qgsmeshlayer.h:94
qgsmaplayer.h
QgsMeshLayer::LayerOptions::LayerOptions
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Definition: qgsmeshlayer.h:109
QgsMeshDataProvider
Definition: qgsmeshdataprovider.h:351
QgsMapLayerTemporalProperties
Definition: qgsmaplayertemporalproperties.h:42
QgsMesh3dAveragingMethod
Definition: qgsmesh3daveraging.h:39
QgsMeshSimplificationSettings
Definition: qgsmeshsimplificationsettings.h:39
QgsPointXY
Definition: qgspointxy.h:43
qgsmeshrenderersettings.h
QgsMeshRendererScalarSettings
Definition: qgsmeshrenderersettings.h:94
QgsMeshDatasetGroupMetadata
Definition: qgsmeshdataset.h:348
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsInterval
A representation of the interval between two datetime values.
Definition: qgsinterval.h:40
QgsTriangularMesh
Definition: qgstriangularmesh.h:49
QgsCoordinateTransform
Definition: qgscoordinatetransform.h:52
qgsmeshdataprovider.h