QGIS API Documentation 3.99.0-Master (26c88405ac0)
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"
26#include "qgsinterval.h"
27#include "qgsmaplayer.h"
28#include "qgsmeshdataprovider.h"
31#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
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;
180 QgsAbstractProfileSource *profileSource() override {return this;}
181 QString profileSourceId() const override {return id();}
182 QString profileSourceName() const override {return name();}
184 bool readSymbology( const QDomNode &node, QString &errorMessage,
186 bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
187 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
188 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const override;
189 bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
190 QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
191 QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
192 bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
193 bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
196 void reload() override;
197 QStringList subLayers() const override;
198 QString htmlMetadata() const override;
199 bool isEditable() const override;
200 bool supportsEditing() const override;
201 QString loadDefaultStyle( bool &resultFlag SIP_OUT ) final;
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;
312
319 void setRendererSettings( const QgsMeshRendererSettings &settings, const bool repaint = true );
320
326 QgsMeshTimeSettings timeSettings() const;
327
333 void setTimeSettings( const QgsMeshTimeSettings &settings );
334
340 QgsMeshSimplificationSettings meshSimplificationSettings() const SIP_SKIP;
341
347 void setMeshSimplificationSettings( const QgsMeshSimplificationSettings &meshSimplificationSettings ) SIP_SKIP;
348
355 QString formatTime( double hours );
356
362 int datasetGroupCount() const;
363
369 int extraDatasetGroupCount() const;
370
379 QList<int> datasetGroupsIndexes() const;
380
389 QList<int> enabledDatasetGroupsIndexes() const;
390
399 QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
400
411 int datasetCount( const QgsMeshDatasetIndex &index ) const;
412
423 QgsMeshDatasetMetadata datasetMetadata( const QgsMeshDatasetIndex &index ) const;
424
442 QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, int valueIndex ) const;
443
462 QgsMeshDataBlock datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const;
463
480 QgsMesh3DDataBlock dataset3dValues( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
481
489 bool isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const;
490
503 QgsMeshDataBlock areFacesActive( const QgsMeshDatasetIndex &index, int faceIndex, int count ) const;
504
527 QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius = 0 ) const;
528
548 QgsMesh3DDataBlock dataset3dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
549
569 QgsMeshDatasetValue dataset1dValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius ) const;
570
586 QgsMeshDatasetIndex datasetIndexAtTime( const QgsDateTimeRange &timeRange, int datasetGroupIndex ) const;
587
603 QgsMeshDatasetIndex datasetIndexAtRelativeTime( const QgsInterval &relativeTime, int datasetGroupIndex ) const;
604
619 QList<QgsMeshDatasetIndex> datasetIndexInRelativeTimeInterval( const QgsInterval &startRelativeTime, const QgsInterval &endRelativeTime, int datasetGroupIndex ) const;
620
632 QgsMeshDatasetIndex activeScalarDatasetAtTime( const QgsDateTimeRange &timeRange, int group = -1 ) const;
633
645 QgsMeshDatasetIndex activeVectorDatasetAtTime( const QgsDateTimeRange &timeRange, int group = -1 ) const;
646
654 void setStaticScalarDatasetIndex( const QgsMeshDatasetIndex &staticScalarDatasetIndex ) SIP_SKIP;
655
663 void setStaticVectorDatasetIndex( const QgsMeshDatasetIndex &staticVectorDatasetIndex ) SIP_SKIP;
664
673 QgsMeshDatasetIndex staticScalarDatasetIndex( int group = -1 ) const;
674
683 QgsMeshDatasetIndex staticVectorDatasetIndex( int group = -1 ) const;
684
692 void setReferenceTime( const QDateTime &referenceTime );
693
701 void setTemporalMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );
702
724 QgsPointXY snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius );
725
752 int closestElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint SIP_OUT ) const;
753
762 QList<int> selectVerticesByExpression( QgsExpression expression );
763
772 QList<int> selectFacesByExpression( QgsExpression expression );
773
781 QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem() const;
782
796 void setDatasetGroupTreeRootItem( QgsMeshDatasetGroupTreeItem *rootItem );
797
803 void resetDatasetGroupTreeItem();
804
810 QgsInterval firstValidTimeStep() const;
811
817 QgsInterval datasetRelativeTime( const QgsMeshDatasetIndex &index );
818
824 qint64 datasetRelativeTimeInMilliseconds( const QgsMeshDatasetIndex &index );
825
833 Q_DECL_DEPRECATED bool startFrameEditing( const QgsCoordinateTransform &transform );
834
845 bool startFrameEditing( const QgsCoordinateTransform &transform, QgsMeshEditingError &error SIP_OUT, bool fixErrors );
846
847
856 bool commitFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
857
866 bool rollBackFrameEditing( const QgsCoordinateTransform &transform, bool continueEditing = true );
867
875 void stopFrameEditing( const QgsCoordinateTransform &transform );
876
886 bool reindex( const QgsCoordinateTransform &transform, bool renumber );
887
893 QgsMeshEditor *meshEditor();
894
900 bool isModified() const override;
901
906 bool contains( const QgsMesh::ElementType &type ) const;
907
915 int meshVertexCount() const;
916
924 int meshFaceCount() const;
925
931 int meshEdgeCount() const;
932
941 bool labelsEnabled() const;
942
953 void setLabelsEnabled( bool enabled );
954
963 const QgsAbstractMeshLayerLabeling *labeling() const SIP_SKIP { return mLabeling; }
964
971 QgsAbstractMeshLayerLabeling *labeling() { return mLabeling; }
972
977 void setLabeling( QgsAbstractMeshLayerLabeling *labeling SIP_TRANSFER );
978
988 bool minimumMaximumActiveScalarDataset( const QgsRectangle &extent, const QgsMeshDatasetIndex &datasetIndex, double &min SIP_OUT, double &max SIP_OUT );
989
995 QgsMeshDatasetIndex activeScalarDatasetIndex( QgsRenderContext &rendererContext );
996
1006 bool datasetsPathUnique( const QString &path );
1007
1008 public slots:
1009
1015 void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
1016
1017 signals:
1018
1025
1032
1039
1045 void reloaded();
1046
1047 private: // Private methods
1048
1052 bool isReadOnly() const override {return true;}
1053
1060 bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags = Qgis::DataProviderReadFlags() );
1061#ifdef SIP_RUN
1062 QgsMeshLayer( const QgsMeshLayer &rhs );
1063#endif
1064
1065 void fillNativeMesh();
1066 void assignDefaultStyleToDatasetGroup( int groupIndex );
1067 void createSimplifiedMeshes();
1068 int levelsOfDetailsIndex( double partOfMeshInView ) const;
1069
1070 bool hasSimplifiedMeshes() const;
1071
1073 void applyClassificationOnScalarSettings( const QgsMeshDatasetGroupMetadata &meta, QgsMeshRendererScalarSettings &scalarSettings ) const;
1074
1075 private slots:
1076 void onDatasetGroupsAdded( const QList<int> &datasetGroupIndexes );
1077 void onMeshEdited();
1078
1079 private:
1081 QgsMeshDataProvider *mDataProvider = nullptr;
1082
1084 QStringList mExtraDatasetUri;
1085
1086 std::unique_ptr<QgsMeshDatasetGroupStore> mDatasetGroupStore;
1087
1089 std::unique_ptr<QgsMesh> mNativeMesh;
1090
1092 std::vector<std::unique_ptr<QgsTriangularMesh>> mTriangularMeshes;
1093
1095 std::unique_ptr<QgsMeshLayerRendererCache> mRendererCache;
1096
1098 QgsMeshRendererSettings mRendererSettings;
1099
1101 QgsMeshTimeSettings mTimeSettings;
1102
1104 QgsMeshSimplificationSettings mSimplificationSettings;
1105
1106 QgsMeshLayerTemporalProperties *mTemporalProperties = nullptr;
1107 QgsMeshLayerElevationProperties *mElevationProperties = nullptr;
1108
1111
1112 int mStaticScalarDatasetIndex = 0;
1113 int mStaticVectorDatasetIndex = 0;
1114
1115 QgsMeshEditor *mMeshEditor = nullptr;
1116
1118 bool mLabelsEnabled = false;
1119
1121 QgsAbstractMeshLayerLabeling *mLabeling = nullptr;
1122
1124 int closestEdge( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
1125
1127 int closestVertex( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
1128
1130 int closestFace( const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint ) const;
1131
1132 void updateActiveDatasetGroups();
1133
1134 QgsMeshRendererSettings accordSymbologyWithGroupName( const QgsMeshRendererSettings &settings, const QMap<QString, int> &nameToIndex );
1135 void checkSymbologyConsistency();
1136
1137 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
1139};
1140
1141#endif //QGSMESHLAYER_H
TemporalUnit
Temporal units.
Definition qgis.h:5159
@ Hours
Hours.
Definition qgis.h:5163
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:486
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.
virtual QgsAbstractProfileGenerator * createProfileGenerator(const QgsProfileRequest &request)=0
Given a profile request, returns a new profile generator ready for generating elevation profiles.
Contains information about the context in which a coordinate transform is executed.
Handles coordinate transforms between two coordinate systems.
Handles parsing and evaluation of expressions (formerly called "search strings").
A representation of the interval between two datetime values.
Definition qgsinterval.h:47
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.
QString name
Definition qgsmaplayer.h:84
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the document provided.
virtual QString encodedSource(const QString &source, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
virtual bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files.
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by children to write state specific to them to project files.
QString id
Definition qgsmaplayer.h:83
QgsMapLayer(Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
virtual bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read the style for the current layer from the DOM node supplied.
virtual bool supportsEditing() const
Returns whether the layer supports editing or not.
QFlags< StyleCategory > StyleCategories
virtual bool isEditable() const
Returns true if the layer can be edited.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
virtual QStringList subLayers() const
Returns the sublayers of this layer.
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
Read the symbology for the current layer from the DOM node supplied.
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
virtual QString decodedSource(const QString &source, const QString &dataProvider, const QgsReadWriteContext &context) const
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
virtual bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write just the symbology information for the layer into the document.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
Abstract class for interpolating 3d stacked mesh data to 2d data.
A block of 3d stacked mesh data related N faces defined on base mesh frame.
A block of integers/doubles from a mesh dataset.
Handles properties relating to a mesh data provider's temporal capabilities.
Base class for providing data for QgsMeshLayer.
A collection of dataset group metadata such as whether the data is vector or scalar,...
Registers and accesses 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.
An index that identifies the dataset group (e.g.
Represents mesh dataset metadata, such as whether the data is valid or the associated time.
Represents a single mesh dataset value.
Represents an error which occurred during mesh editing.
Handles edit operations on a mesh layer.
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.
QString profileSourceName() const override
Returns a name for displaying this profile source in the elevation profile layer tree.
QgsRectangle extent() const override
Returns the extent of the layer.
QgsAbstractProfileSource * profileSource() override
Returns the layer's profile source if it has profile capabilities.
void activeScalarDatasetGroupChanged(int index)
Emitted when active scalar group dataset is changed.
void activeVectorDatasetGroupChanged(int index)
Emitted when active vector group dataset is changed.
const QgsAbstractMeshLayerLabeling * labeling() const
Access to const labeling configuration.
QgsMeshLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
void timeSettingsChanged()
Emitted when time format is changed.
QgsMeshLayer & operator=(QgsMeshLayer const &rhs)=delete
QgsMeshLayer(const QgsMeshLayer &rhs)=delete
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
QString profileSourceId() const override
Returns a unique identifier for this profile source.
QgsAbstractMeshLayerLabeling * labeling()
Access to labeling configuration.
void reloaded()
Emitted when the mesh layer is reloaded, see reload().
QgsMeshLayer(const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib=QStringLiteral("mesh_memory"), const QgsMeshLayer::LayerOptions &options=QgsMeshLayer::LayerOptions())
Constructor - creates a mesh layer.
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.
Represents a 2D point.
Definition qgspointxy.h:60
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
A container for the context for various read/write operations on 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
A triangular/derived mesh with vertices in map coordinates.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:84
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:761
Setting options for creating vector data providers.
Setting options for loading mesh layers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Mesh - vertices, edges and faces.