QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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;
46
100class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSource
101{
102 Q_OBJECT
103 public:
104
109 {
110
116 : transformContext( transformContext )
117 {}
118
123
128 bool loadDefaultStyle = true;
129
143 bool skipCrsValidation = false;
144 };
145
159 explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = QStringLiteral( "mesh_memory" ),
161
162 ~QgsMeshLayer() override;
163
164 QgsMeshLayer( const QgsMeshLayer &rhs ) = delete;
165 QgsMeshLayer &operator=( QgsMeshLayer const &rhs ) = delete;
166
167#ifdef SIP_RUN
168 SIP_PYOBJECT __repr__();
169 % MethodCode
170 QString str = QStringLiteral( "<QgsMeshLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
171 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
172 % End
173#endif
174
176 const QgsMeshDataProvider *dataProvider() const override SIP_SKIP;
177 QgsMeshLayer *clone() const override SIP_FACTORY;
178 QgsRectangle extent() const override;
179 QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
180 QgsAbstractProfileGenerator *createProfileGenerator( const QgsProfileRequest &request ) override SIP_FACTORY;
181 bool readSymbology( const QDomNode &node, QString &errorMessage,
182 QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
183 bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
184 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
185 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const override;
186 bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
187 QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
188 QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
189 bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
190 bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
191 QgsMapLayerTemporalProperties *temporalProperties() override;
192 QgsMapLayerElevationProperties *elevationProperties() override;
193 void reload() override;
194 QStringList subLayers() const override;
195 QString htmlMetadata() const override;
196 bool isEditable() const override;
197 bool supportsEditing() const override;
198 QString loadDefaultStyle( bool &resultFlag SIP_OUT ) FINAL;
199
201 QString providerType() const;
202
212 bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );
213
222 bool addDatasets( QgsMeshDatasetGroup *datasetGroup SIP_TRANSFER );
223
234 bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
235
241 QgsMesh *nativeMesh() SIP_SKIP;
242
248 const QgsMesh *nativeMesh() const SIP_SKIP;
249
262 QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
263
270 int triangularMeshLevelOfDetailCount() const SIP_SKIP;
271
282 QgsTriangularMesh *triangularMeshByLodIndex( int lodIndex ) const SIP_SKIP;
283
291 void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
292
298 QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
299
301 QgsMeshRendererSettings rendererSettings() const;
303 void setRendererSettings( const QgsMeshRendererSettings &settings );
304
310 QgsMeshTimeSettings timeSettings() const;
311
317 void setTimeSettings( const QgsMeshTimeSettings &settings );
318
324 QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
325
331 void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
332
339 QString formatTime( double hours );
340
346 int datasetGroupCount() const;
347
353 int extraDatasetGroupCount() const;
354
363 QList<int> datasetGroupsIndexes() const;
364
373 QList<int> enabledDatasetGroupsIndexes() const;
374
383 QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
384
395 int datasetCount( const QgsMeshDatasetIndex &index ) const;
396
407 QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
408
426 QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
427
446 QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
447
464 QgsMesh3DDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
465
473 bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
474
487 QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
488
511 QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
512
532 QgsMesh3DDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
533
553 QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
554
570 QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
571
587 QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
588
603 QList<QgsMeshDatasetIndex> datasetIndexInRelativeTimeInterval( const QgsInterval &startRelativeTime, const QgsInterval &endRelativeTime, int datasetGroupIndex ) const;
604
616 QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange, int group = -1 ) const;
617
629 QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange, int group = -1 ) const;
630
638 void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
639
647 void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
648
657 QgsMeshDatasetIndex staticScalarDatasetIndex( int group = -1 ) const;
658
667 QgsMeshDatasetIndex staticVectorDatasetIndex( int group = -1 ) const;
668
676 void setReferenceTime( const QDateTime &referenceTime );
677
685 void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
686
708 QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
709
718 QList<int> selectVerticesByExpression( QgsExpression expression );
719
728 QList<int> selectFacesByExpression( QgsExpression expression );
729
737 QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
738
752 void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
753
759 void resetDatasetGroupTreeItem();
760
766 QgsInterval firstValidTimeStep() const;
767
773 QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
774
780 qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
781
789 Q_DECL_DEPRECATED bool startFrameEditing( const QgsCoordinateTransform &transform );
790
801 bool startFrameEditing( const QgsCoordinateTransform &transform, QgsMeshEditingError &error SIP_OUT, bool fixErrors );
802
803
812 bool commitFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
813
822 bool rollBackFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
823
831 void stopFrameEditing( const QgsCoordinateTransform &transform );
832
842 bool reindex( const QgsCoordinateTransform &transform, bool renumber );
843
849 QgsMeshEditor *meshEditor();
850
856 bool isModified() const override;
857
862 bool contains( const QgsMesh::ElementType &type ) const;
863
871 int meshVertexCount() const;
872
880 int meshFaceCount() const;
881
887 int meshEdgeCount() const;
888
897 bool labelsEnabled() const;
898
909 void setLabelsEnabled( bool enabled );
910
919 const QgsAbstractMeshLayerLabeling *labeling() const SIP_SKIP { return mLabeling; }
920
927 QgsAbstractMeshLayerLabeling *labeling() { return mLabeling; }
928
933 void setLabeling( QgsAbstractMeshLayerLabeling *labeling SIP_TRANSFER );
934
935
936 public slots:
937
943 void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
944
945 signals:
946
953
960
967
973 void reloaded();
974
975 private: // Private methods
976
980 bool isReadOnly() const override {return true;}
981
988 bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags = Qgis::DataProviderReadFlags() );
989
990#ifdef SIP_RUN
991 QgsMeshLayer( const QgsMeshLayer &rhs );
992#endif
993
994 void fillNativeMesh();
995 void assignDefaultStyleToDatasetGroup( int groupIndex );
996 void createSimplifiedMeshes();
997 int levelsOfDetailsIndex( double partOfMeshInView ) const;
998
999 bool hasSimplifiedMeshes() const;
1000
1002 void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
1003
1004 private slots:
1005 void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
1006 void onMeshEdited();
1007
1008 private:
1010 QgsMeshDataProvider *mDataProvider = nullptr;
1011
1013 QStringList mExtraDatasetUri;
1014
1015 std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
1016
1018 std::unique_ptr<QgsMesh> mNativeMesh;
1019
1021 std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
1022
1024 std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
1025
1027 QgsMeshRendererSettings mRendererSettings;
1028
1030 QgsMeshTimeSettings mTimeSettings;
1031
1033 QgsMeshSimplificationSettings mSimplificationSettings;
1034
1035 QgsMeshLayerTemporalProperties *mTemporalProperties = nullptr;
1036 QgsMeshLayerElevationProperties *mElevationProperties = nullptr;
1037
1040
1041 int mStaticScalarDatasetIndex = 0;
1042 int mStaticVectorDatasetIndex = 0;
1043
1044 QgsMeshEditor *mMeshEditor = nullptr;
1045
1047 bool mLabelsEnabled = false;
1048
1050 QgsAbstractMeshLayerLabeling *mLabeling = nullptr;
1051
1052 int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
1053
1055 QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
1056
1058 QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
1059
1061 QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
1062
1063 void updateActiveDatasetGroups();
1064
1065 QgsMeshRendererSettings accordSymbologyWithGroupName( const QgsMeshRendererSettings &settings, const QMap<QString, int> &nameToIndex );
1066 void checkSymbologyConsistency();
1067
1068 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
1070};
1071
1072#endif //QGSMESHLAYER_H
TemporalUnit
Temporal units.
Definition qgis.h:4823
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
Abstract base class - its implementations define different approaches to the labeling of a mesh layer...
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:46
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:76
QFlags< StyleCategory > StyleCategories
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
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.
Class that makes edit operation on a mesh.
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.
void activeScalarDatasetGroupChanged(int index)
Emitted when active scalar group dataset is changed.
void activeVectorDatasetGroupChanged(int index)
Emitted when active vector group dataset is changed.
void timeSettingsChanged()
Emitted when time format is changed.
QgsMeshLayer & operator=(QgsMeshLayer const &rhs)=delete
QgsMeshLayer(const QgsMeshLayer &rhs)=delete
QgsAbstractMeshLayerLabeling * labeling()
Access to labeling configuration.
void reloaded()
Emitted when the mesh layer is reloaded, see reload()
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:60
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.
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Triangular/Derived Mesh is mesh with vertices in map coordinates.
#define str(x)
Definition qgis.cpp:39
#define SIP_SKIP
Definition qgis_sip.h:126
#define FINAL
Definition qgis_sip.h:242
#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.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Mesh - vertices, edges and faces.