QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 removeDatasets( const QString &name );
223
232 bool addDatasets( QgsMeshDatasetGroup *datasetGroup SIP_TRANSFER );
233
244 bool saveDataset( const QString &path, int datasetGroupIndex, QString driver );
245
251 QgsMesh *nativeMesh() SIP_SKIP;
252
258 const QgsMesh *nativeMesh() const SIP_SKIP;
259
272 QgsTriangularMesh *triangularMesh( double minimumTriangleSize = 0 ) const SIP_SKIP;
273
280 int triangularMeshLevelOfDetailCount() const SIP_SKIP;
281
292 QgsTriangularMesh *triangularMeshByLodIndex( int lodIndex ) const SIP_SKIP;
293
301 void updateTriangularMesh( const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
302
308 QgsMeshLayerRendererCache *rendererCache() SIP_SKIP;
309
311 QgsMeshRendererSettings rendererSettings() const;
313 void setRendererSettings( const QgsMeshRendererSettings &settings );
314
320 QgsMeshTimeSettings timeSettings() const;
321
327 void setTimeSettings( const QgsMeshTimeSettings &settings );
328
334 QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
335
341 void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
342
349 QString formatTime( double hours );
350
356 int datasetGroupCount() const;
357
363 int extraDatasetGroupCount() const;
364
373 QList<int> datasetGroupsIndexes() const;
374
383 QList<int> enabledDatasetGroupsIndexes() const;
384
393 QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
394
405 int datasetCount( const QgsMeshDatasetIndex &index ) const;
406
417 QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
418
436 QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
437
456 QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
457
474 QgsMesh3DDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
475
483 bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
484
497 QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
498
521 QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
522
542 QgsMesh3DDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
543
563 QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
564
580 QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
581
597 QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
598
613 QList<QgsMeshDatasetIndex> datasetIndexInRelativeTimeInterval( const QgsInterval &startRelativeTime, const QgsInterval &endRelativeTime, int datasetGroupIndex ) const;
614
626 QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange, int group = -1 ) const;
627
639 QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange, int group = -1 ) const;
640
648 void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
649
657 void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
658
667 QgsMeshDatasetIndex staticScalarDatasetIndex( int group = -1 ) const;
668
677 QgsMeshDatasetIndex staticVectorDatasetIndex( int group = -1 ) const;
678
686 void setReferenceTime( const QDateTime &referenceTime );
687
695 void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
696
718 QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
719
728 QList<int> selectVerticesByExpression( QgsExpression expression );
729
738 QList<int> selectFacesByExpression( QgsExpression expression );
739
747 QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
748
762 void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
763
769 void resetDatasetGroupTreeItem();
770
776 QgsInterval firstValidTimeStep() const;
777
783 QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
784
790 qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
791
799 Q_DECL_DEPRECATED bool startFrameEditing( const QgsCoordinateTransform &transform );
800
811 bool startFrameEditing( const QgsCoordinateTransform &transform, QgsMeshEditingError &error SIP_OUT, bool fixErrors );
812
813
822 bool commitFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
823
832 bool rollBackFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
833
841 void stopFrameEditing( const QgsCoordinateTransform &transform );
842
852 bool reindex( const QgsCoordinateTransform &transform, bool renumber );
853
859 QgsMeshEditor *meshEditor();
860
866 bool isModified() const override;
867
872 bool contains( const QgsMesh::ElementType &type ) const;
873
881 int meshVertexCount() const;
882
890 int meshFaceCount() const;
891
897 int meshEdgeCount() const;
898
907 bool labelsEnabled() const;
908
919 void setLabelsEnabled( bool enabled );
920
929 const QgsAbstractMeshLayerLabeling *labeling() const SIP_SKIP { return mLabeling; }
930
937 QgsAbstractMeshLayerLabeling *labeling() { return mLabeling; }
938
943 void setLabeling( QgsAbstractMeshLayerLabeling *labeling SIP_TRANSFER );
944
954 bool datasetsPathUnique( const QString &path );
955
956 public slots:
957
963 void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
964
965 signals:
966
973
980
987
993 void reloaded();
994
995 private: // Private methods
996
1000 bool isReadOnly() const override {return true;}
1001
1008 bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags = Qgis::DataProviderReadFlags() );
1009#ifdef SIP_RUN
1010 QgsMeshLayer( const QgsMeshLayer &rhs );
1011#endif
1012
1013 void fillNativeMesh();
1014 void assignDefaultStyleToDatasetGroup( int groupIndex );
1015 void createSimplifiedMeshes();
1016 int levelsOfDetailsIndex( double partOfMeshInView ) const;
1017
1018 bool hasSimplifiedMeshes() const;
1019
1021 void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
1022
1023 private slots:
1024 void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
1025 void onMeshEdited();
1026
1027 private:
1029 QgsMeshDataProvider *mDataProvider = nullptr;
1030
1032 QStringList mExtraDatasetUri;
1033
1034 std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
1035
1037 std::unique_ptr<QgsMesh> mNativeMesh;
1038
1040 std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
1041
1043 std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
1044
1046 QgsMeshRendererSettings mRendererSettings;
1047
1049 QgsMeshTimeSettings mTimeSettings;
1050
1052 QgsMeshSimplificationSettings mSimplificationSettings;
1053
1054 QgsMeshLayerTemporalProperties *mTemporalProperties = nullptr;
1055 QgsMeshLayerElevationProperties *mElevationProperties = nullptr;
1056
1059
1060 int mStaticScalarDatasetIndex = 0;
1061 int mStaticVectorDatasetIndex = 0;
1062
1063 QgsMeshEditor *mMeshEditor = nullptr;
1064
1066 bool mLabelsEnabled = false;
1067
1069 QgsAbstractMeshLayerLabeling *mLabeling = nullptr;
1070
1071 int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
1072
1074 QgsPointXY snapOnVertex( const QgsPointXY &point, double searchRadius );
1075
1077 QgsPointXY snapOnEdge( const QgsPointXY &point, double searchRadius );
1078
1080 QgsPointXY snapOnFace( const QgsPointXY &point, double searchRadius );
1081
1082 void updateActiveDatasetGroups();
1083
1084 QgsMeshRendererSettings accordSymbologyWithGroupName( const QgsMeshRendererSettings &settings, const QMap<QString, int> &nameToIndex );
1085 void checkSymbologyConsistency();
1086
1087 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
1089};
1090
1091#endif //QGSMESHLAYER_H
TemporalUnit
Temporal units.
Definition qgis.h:4868
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 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.