QGIS API Documentation  3.21.0-Master (56b4176581)
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 class QgsMeshEditor;
41 
95 class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
96 {
97  Q_OBJECT
98  public:
99 
104  {
105 
111  : transformContext( transformContext )
112  {}
113 
115 
129  bool skipCrsValidation = false;
130  };
131 
145  explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = QStringLiteral( "mesh_memory" ),
147 
148  ~QgsMeshLayer() override;
149 
151  QgsMeshLayer( const QgsMeshLayer &rhs ) = delete;
153  QgsMeshLayer &operator=( QgsMeshLayer const &rhs ) = delete;
154 
155 #ifdef SIP_RUN
156  SIP_PYOBJECT __repr__();
157  % MethodCode
158  QString str = QStringLiteral( "<QgsMeshLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
159  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
160  % End
161 #endif
162 
163  QgsMeshDataProvider *dataProvider() override;
164  const QgsMeshDataProvider *dataProvider() const override SIP_SKIP;
165  QgsMeshLayer *clone() const override SIP_FACTORY;
166  QgsRectangle extent() const override;
167  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
168  bool readSymbology( const QDomNode &node, QString &errorMessage,
169  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
170  bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
171  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
172  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const override;
173  bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
174  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
175  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
176  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
177  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
178  QgsMapLayerTemporalProperties *temporalProperties() override;
179  void reload() override;
180  QStringList subLayers() const override;
181  QString htmlMetadata() const override;
182  bool isEditable() const override;
183  bool supportsEditing() const override;
184 
186  QString providerType() const;
187 
197  bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );
198 
207  bool addDatasets( QgsMeshDatasetGroup *datasetGroup SIP_TRANSFER );
208 
219  bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
220 
226  QgsMesh *nativeMesh() SIP_SKIP;
227 
233  const QgsMesh *nativeMesh() const SIP_SKIP;
234 
247  QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
248 
255  int triangularMeshLevelOfDetailCount() const SIP_SKIP;
256 
267  QgsTriangularMesh *triangularMeshByLodIndex( int lodIndex ) const SIP_SKIP;
268 
276  void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
277 
283  QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
284 
286  QgsMeshRendererSettings rendererSettings() const;
288  void setRendererSettings( const QgsMeshRendererSettings &settings );
289 
295  QgsMeshTimeSettings timeSettings() const;
296 
302  void setTimeSettings( const QgsMeshTimeSettings &settings );
303 
309  QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
310 
316  void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
317 
324  QString formatTime( double hours );
325 
331  int datasetGroupCount() const;
332 
338  int extraDatasetGroupCount() const;
339 
348  QList<int> datasetGroupsIndexes() const;
349 
358  QList<int> enabledDatasetGroupsIndexes() const;
359 
368  QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
369 
380  int datasetCount( const QgsMeshDatasetIndex &index ) const;
381 
392  QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
393 
411  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
412 
431  QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
432 
449  QgsMesh3dDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
450 
458  bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
459 
472  QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
473 
496  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
497 
517  QgsMesh3dDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
518 
538  QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
539 
555  QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
556 
572  QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
573 
585  QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
586 
598  QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
599 
607  void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
608 
616  void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
617 
623  QgsMeshDatasetIndex staticScalarDatasetIndex() const;
624 
630  QgsMeshDatasetIndex staticVectorDatasetIndex() const;
631 
639  void setReferenceTime( const QDateTime &referenceTime );
640 
648  void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
649 
671  QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
672 
681  QList<int> selectVerticesByExpression( QgsExpression expression );
682 
691  QList<int> selectFacesByExpression( QgsExpression expression );
692 
700  QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
701 
715  void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
716 
722  void resetDatasetGroupTreeItem();
723 
729  QgsInterval firstValidTimeStep() const;
730 
736  QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
737 
743  qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
744 
751  bool startFrameEditing( const QgsCoordinateTransform &transform );
752 
761  bool commitFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
762 
771  bool rollBackFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
772 
780  void stopFrameEditing( const QgsCoordinateTransform &transform );
781 
791  bool reindex( const QgsCoordinateTransform &transform, bool renumber );
792 
798  QgsMeshEditor *meshEditor();
799 
805  bool isModified() const override;
806 
811  bool contains( const QgsMesh::ElementType &type ) const;
812 
820  int meshVertexCount() const;
821 
829  int meshFaceCount() const;
830 
836  int meshEdgeCount() const;
837 
838  public slots:
839 
845  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
846 
847  signals:
848 
854  void activeScalarDatasetGroupChanged( int index );
855 
861  void activeVectorDatasetGroupChanged( int index );
862 
868  void timeSettingsChanged( );
869 
870  private: // Private methods
871 
875  bool isReadOnly() const override {return true;}
876 
883  bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
884 
885 #ifdef SIP_RUN
886  QgsMeshLayer( const QgsMeshLayer &rhs );
887 #endif
888 
889  void fillNativeMesh();
890  void assignDefaultStyleToDatasetGroup( int groupIndex );
891  void setDefaultRendererSettings( const QList<int> &groupIndexes );
892  void createSimplifiedMeshes();
893  int levelsOfDetailsIndex( double partOfMeshInView ) const;
894 
895  bool hasSimplifiedMeshes() const;
896 
898  void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
899 
900  private slots:
901  void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
902  void onMeshEdited();
903 
904  private:
906  QgsMeshDataProvider *mDataProvider = nullptr;
907 
909  QStringList mExtraDatasetUri;
910 
911  std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
912 
914  std::unique_ptr<QgsMesh> mNativeMesh;
915 
917  std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
918 
920  std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
921 
923  QgsMeshRendererSettings mRendererSettings;
924 
926  QgsMeshTimeSettings mTimeSettings;
927 
929  QgsMeshSimplificationSettings mSimplificationSettings;
930 
931  QgsMeshLayerTemporalProperties *mTemporalProperties = nullptr;
932 
935 
936  int mStaticScalarDatasetIndex = 0;
937  int mStaticVectorDatasetIndex = 0;
938 
939  QgsMeshEditor *mMeshEditor = nullptr;
940 
941  int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
942 
944  QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
945 
947  QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
948 
950  QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
951 
952  void updateActiveDatasetGroups();
953 
954  void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
955  const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags ) override;
956 };
957 
958 #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:72
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:96
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:104
QgsCoordinateTransformContext transformContext
Definition: qgsmeshlayer.h:114
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Definition: qgsmeshlayer.h:110
Mesh - vertices, edges and faces.