QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 #include "qgscoordinatetransform.h"
31 
33 struct QgsMeshLayerRendererCache;
34 class QgsSymbol;
35 class QgsTriangularMesh;
36 class QgsRenderContext;
37 struct QgsMesh;
41 class QgsMeshEditor;
42 
96 class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
97 {
98  Q_OBJECT
99  public:
100 
105  {
106 
112  : transformContext( transformContext )
113  {}
114 
119 
124  bool loadDefaultStyle = true;
125 
139  bool skipCrsValidation = false;
140  };
141 
155  explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = QStringLiteral( "mesh_memory" ),
157 
158  ~QgsMeshLayer() override;
159 
161  QgsMeshLayer( const QgsMeshLayer &rhs ) = delete;
163  QgsMeshLayer &operator=( QgsMeshLayer const &rhs ) = delete;
164 
165 #ifdef SIP_RUN
166  SIP_PYOBJECT __repr__();
167  % MethodCode
168  QString str = QStringLiteral( "<QgsMeshLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
169  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
170  % End
171 #endif
172 
173  QgsMeshDataProvider *dataProvider() override;
174  const QgsMeshDataProvider *dataProvider() const override SIP_SKIP;
175  QgsMeshLayer *clone() const override SIP_FACTORY;
176  QgsRectangle extent() const override;
177  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
178  bool readSymbology( const QDomNode &node, QString &errorMessage,
179  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
180  bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
181  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
182  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const override;
183  bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
184  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
185  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
186  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
187  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
188  QgsMapLayerTemporalProperties *temporalProperties() override;
189  void reload() override;
190  QStringList subLayers() const override;
191  QString htmlMetadata() const override;
192  bool isEditable() const override;
193  bool supportsEditing() const override;
194  QString loadDefaultStyle( bool &resultFlag SIP_OUT ) FINAL;
195 
197  QString providerType() const;
198 
208  bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );
209 
218  bool addDatasets( QgsMeshDatasetGroup *datasetGroup SIP_TRANSFER );
219 
230  bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
231 
237  QgsMesh *nativeMesh() SIP_SKIP;
238 
244  const QgsMesh *nativeMesh() const SIP_SKIP;
245 
258  QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
259 
266  int triangularMeshLevelOfDetailCount() const SIP_SKIP;
267 
278  QgsTriangularMesh *triangularMeshByLodIndex( int lodIndex ) const SIP_SKIP;
279 
287  void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
288 
294  QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
295 
297  QgsMeshRendererSettings rendererSettings() const;
299  void setRendererSettings( const QgsMeshRendererSettings &settings );
300 
306  QgsMeshTimeSettings timeSettings() const;
307 
313  void setTimeSettings( const QgsMeshTimeSettings &settings );
314 
320  QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
321 
327  void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
328 
335  QString formatTime( double hours );
336 
342  int datasetGroupCount() const;
343 
349  int extraDatasetGroupCount() const;
350 
359  QList<int> datasetGroupsIndexes() const;
360 
369  QList<int> enabledDatasetGroupsIndexes() const;
370 
379  QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
380 
391  int datasetCount( const QgsMeshDatasetIndex &index ) const;
392 
403  QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
404 
422  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
423 
442  QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
443 
460  QgsMesh3dDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
461 
469  bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
470 
483  QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
484 
507  QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
508 
528  QgsMesh3dDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
529 
549  QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
550 
566  QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
567 
583  QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
584 
599  QList<QgsMeshDatasetIndex> datasetIndexInRelativeTimeInterval( const QgsInterval &startRelativeTime, const QgsInterval &endRelativeTime, int datasetGroupIndex ) const;
600 
612  QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
613 
625  QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
626 
634  void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
635 
643  void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
644 
650  QgsMeshDatasetIndex staticScalarDatasetIndex() const;
651 
657  QgsMeshDatasetIndex staticVectorDatasetIndex() const;
658 
666  void setReferenceTime( const QDateTime &referenceTime );
667 
675  void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
676 
698  QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
699 
708  QList<int> selectVerticesByExpression( QgsExpression expression );
709 
718  QList<int> selectFacesByExpression( QgsExpression expression );
719 
727  QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
728 
742  void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
743 
749  void resetDatasetGroupTreeItem();
750 
756  QgsInterval firstValidTimeStep() const;
757 
763  QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
764 
770  qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
771 
778  bool startFrameEditing( const QgsCoordinateTransform &transform );
779 
788  bool commitFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
789 
798  bool rollBackFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
799 
807  void stopFrameEditing( const QgsCoordinateTransform &transform );
808 
818  bool reindex( const QgsCoordinateTransform &transform, bool renumber );
819 
825  QgsMeshEditor *meshEditor();
826 
832  bool isModified() const override;
833 
838  bool contains( const QgsMesh::ElementType &type ) const;
839 
847  int meshVertexCount() const;
848 
856  int meshFaceCount() const;
857 
863  int meshEdgeCount() const;
864 
865  public slots:
866 
872  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
873 
874  signals:
875 
881  void activeScalarDatasetGroupChanged( int index );
882 
888  void activeVectorDatasetGroupChanged( int index );
889 
895  void timeSettingsChanged( );
896 
897  private: // Private methods
898 
902  bool isReadOnly() const override {return true;}
903 
910  bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
911 
912 #ifdef SIP_RUN
913  QgsMeshLayer( const QgsMeshLayer &rhs );
914 #endif
915 
916  void fillNativeMesh();
917  void assignDefaultStyleToDatasetGroup( int groupIndex );
918  void setDefaultRendererSettings( const QList<int> &groupIndexes );
919  void createSimplifiedMeshes();
920  int levelsOfDetailsIndex( double partOfMeshInView ) const;
921 
922  bool hasSimplifiedMeshes() const;
923 
925  void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
926 
927  private slots:
928  void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
929  void onMeshEdited();
930 
931  private:
933  QgsMeshDataProvider *mDataProvider = nullptr;
934 
936  QStringList mExtraDatasetUri;
937 
938  std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
939 
941  std::unique_ptr<QgsMesh> mNativeMesh;
942 
944  std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
945 
947  std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
948 
950  QgsMeshRendererSettings mRendererSettings;
951 
953  QgsMeshTimeSettings mTimeSettings;
954 
956  QgsMeshSimplificationSettings mSimplificationSettings;
957 
958  QgsMeshLayerTemporalProperties *mTemporalProperties = nullptr;
959 
962 
963  int mStaticScalarDatasetIndex = 0;
964  int mStaticVectorDatasetIndex = 0;
965 
966  QgsMeshEditor *mMeshEditor = nullptr;
967 
968  int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
969 
971  QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
972 
974  QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
975 
977  QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
978 
979  void updateActiveDatasetGroups();
980 
981  void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
982  const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags ) override;
983 };
984 
985 #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:73
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:68
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:97
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 FINAL
Definition: qgis_sip.h:228
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
Setting options for creating vector data providers.
Setting options for loading mesh layers.
Definition: qgsmeshlayer.h:105
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsmeshlayer.h:118
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Definition: qgsmeshlayer.h:111
Mesh - vertices, edges and faces.