QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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"
32
34struct QgsMeshLayerRendererCache;
35class QgsSymbol;
38struct QgsMesh;
42class QgsMeshEditor;
45
99class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSource
100{
101 Q_OBJECT
102 public:
103
108 {
109
115 : transformContext( transformContext )
116 {}
117
122
127 bool loadDefaultStyle = true;
128
142 bool skipCrsValidation = false;
143 };
144
158 explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = QStringLiteral( "mesh_memory" ),
160
161 ~QgsMeshLayer() override;
162
164 QgsMeshLayer( const QgsMeshLayer &rhs ) = delete;
166 QgsMeshLayer &operator=( QgsMeshLayer const &rhs ) = delete;
167
168#ifdef SIP_RUN
169 SIP_PYOBJECT __repr__();
170 % MethodCode
171 QString str = QStringLiteral( "<QgsMeshLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
172 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
173 % End
174#endif
175
177 const QgsMeshDataProvider *dataProvider() const override SIP_SKIP;
178 QgsMeshLayer *clone() const override SIP_FACTORY;
179 QgsRectangle extent() const override;
180 QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
181 QgsAbstractProfileGenerator *createProfileGenerator( const QgsProfileRequest &request ) override SIP_FACTORY;
182 bool readSymbology( const QDomNode &node, QString &errorMessage,
183 QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
184 bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
185 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
186 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const override;
187 bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
188 QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
189 QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
190 bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
191 bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
192 QgsMapLayerTemporalProperties *temporalProperties() override;
193 QgsMapLayerElevationProperties *elevationProperties() override;
194 void reload() override;
195 QStringList subLayers() const override;
196 QString htmlMetadata() const override;
197 bool isEditable() const override;
198 bool supportsEditing() const override;
199 QString loadDefaultStyle( bool &resultFlag SIP_OUT ) FINAL;
200
202 QString providerType() const;
203
213 bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );
214
223 bool addDatasets( QgsMeshDatasetGroup *datasetGroup SIP_TRANSFER );
224
235 bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
236
242 QgsMesh *nativeMesh() SIP_SKIP;
243
249 const QgsMesh *nativeMesh() const SIP_SKIP;
250
263 QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
264
271 int triangularMeshLevelOfDetailCount() const SIP_SKIP;
272
283 QgsTriangularMesh *triangularMeshByLodIndex( int lodIndex ) const SIP_SKIP;
284
292 void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
293
299 QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
300
302 QgsMeshRendererSettings rendererSettings() const;
304 void setRendererSettings( const QgsMeshRendererSettings &settings );
305
311 QgsMeshTimeSettings timeSettings() const;
312
318 void setTimeSettings( const QgsMeshTimeSettings &settings );
319
325 QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
326
332 void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
333
340 QString formatTime( double hours );
341
347 int datasetGroupCount() const;
348
354 int extraDatasetGroupCount() const;
355
364 QList<int> datasetGroupsIndexes() const;
365
374 QList<int> enabledDatasetGroupsIndexes() const;
375
384 QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
385
396 int datasetCount( const QgsMeshDatasetIndex &index ) const;
397
408 QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
409
427 QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
428
447 QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
448
465 QgsMesh3dDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
466
474 bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
475
488 QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
489
512 QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
513
533 QgsMesh3dDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
534
554 QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
555
571 QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
572
588 QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
589
604 QList<QgsMeshDatasetIndex> datasetIndexInRelativeTimeInterval( const QgsInterval &startRelativeTime, const QgsInterval &endRelativeTime, int datasetGroupIndex ) const;
605
617 QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
618
630 QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange ) const;
631
639 void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
640
648 void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
649
655 QgsMeshDatasetIndex staticScalarDatasetIndex() const;
656
662 QgsMeshDatasetIndex staticVectorDatasetIndex() const;
663
671 void setReferenceTime( const QDateTime &referenceTime );
672
680 void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
681
703 QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
704
713 QList<int> selectVerticesByExpression( QgsExpression expression );
714
723 QList<int> selectFacesByExpression( QgsExpression expression );
724
732 QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
733
747 void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
748
754 void resetDatasetGroupTreeItem();
755
761 QgsInterval firstValidTimeStep() const;
762
768 QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
769
775 qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
776
784 Q_DECL_DEPRECATED bool startFrameEditing( const QgsCoordinateTransform &transform );
785
796 bool startFrameEditing( const QgsCoordinateTransform &transform, QgsMeshEditingError &error SIP_OUT, bool fixErrors );
797
798
807 bool commitFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
808
817 bool rollBackFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
818
826 void stopFrameEditing( const QgsCoordinateTransform &transform );
827
837 bool reindex( const QgsCoordinateTransform &transform, bool renumber );
838
844 QgsMeshEditor *meshEditor();
845
851 bool isModified() const override;
852
857 bool contains( const QgsMesh::ElementType &type ) const;
858
866 int meshVertexCount() const;
867
875 int meshFaceCount() const;
876
882 int meshEdgeCount() const;
883
884 public slots:
885
891 void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
892
893 signals:
894
900 void activeScalarDatasetGroupChanged( int index );
901
907 void activeVectorDatasetGroupChanged( int index );
908
914 void timeSettingsChanged();
915
921 void reloaded();
922
923 private: // Private methods
924
928 bool isReadOnly() const override {return true;}
929
936 bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
937
938#ifdef SIP_RUN
939 QgsMeshLayer( const QgsMeshLayer &rhs );
940#endif
941
942 void fillNativeMesh();
943 void assignDefaultStyleToDatasetGroup( int groupIndex );
944 void createSimplifiedMeshes();
945 int levelsOfDetailsIndex( double partOfMeshInView ) const;
946
947 bool hasSimplifiedMeshes() const;
948
950 void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
951
952 private slots:
953 void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
954 void onMeshEdited();
955
956 private:
958 QgsMeshDataProvider *mDataProvider = nullptr;
959
961 QStringList mExtraDatasetUri;
962
963 std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
964
966 std::unique_ptr<QgsMesh> mNativeMesh;
967
969 std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
970
972 std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
973
975 QgsMeshRendererSettings mRendererSettings;
976
978 QgsMeshTimeSettings mTimeSettings;
979
981 QgsMeshSimplificationSettings mSimplificationSettings;
982
983 QgsMeshLayerTemporalProperties *mTemporalProperties = nullptr;
984 QgsMeshLayerElevationProperties *mElevationProperties = nullptr;
985
988
989 int mStaticScalarDatasetIndex = 0;
990 int mStaticVectorDatasetIndex = 0;
991
992 QgsMeshEditor *mMeshEditor = nullptr;
993
994 int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
995
997 QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
998
1000 QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
1001
1003 QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
1004
1005 void updateActiveDatasetGroups();
1006
1007 void checkSymbologyConsistency();
1008
1009 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
1010 const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags ) override;
1011};
1012
1013#endif //QGSMESHLAYER_H
Abstract base class for objects which generate elevation profiles.
Interface for classes which can generate elevation profiles.
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 storage of map layer elevation properties.
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 represents an error during mesh editing.
Definition: qgsmesheditor.h:43
Class that makes edit operation on a mesh.
Definition: qgsmesheditor.h:68
Mesh layer specific subclass of QgsMapLayerElevationProperties.
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:100
QgsMeshLayer & operator=(QgsMeshLayer const &rhs)=delete
QgsMeshLayer cannot be copied.
QgsMeshLayer(const QgsMeshLayer &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
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
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:93
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:237
#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:108
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsmeshlayer.h:121
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Definition: qgsmeshlayer.h:114
Mesh - vertices, edges and faces.