QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsmeshdataprovider.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshdataprovider.cpp
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#include "qgis.h"
19#include "qgsmeshdataprovider.h"
21#include "qgsrectangle.h"
22
24 QgsDataProvider::ReadFlags flags )
25 : QgsDataProvider( uri, options, flags )
26{
27}
28
30{
31 return mTemporalCapabilities.get();
32}
33
35{
36 return mTemporalCapabilities.get();
37}
38
40{
41 const QgsUnitTypes::TemporalUnit oldUnit = mTemporalCapabilities->temporalUnit();
42 mTemporalCapabilities->setTemporalUnit( unit );
43 if ( oldUnit != unit )
44 reloadData();
45}
46
48
50 const QDateTime &referenceTime,
51 int groupIndex, qint64 time,
53{
54 const QDateTime requestDateTime = referenceTime.addMSecs( time );
55 qint64 providerTime;
56 const QDateTime providerReferenceTime = mTemporalCapabilities->referenceTime();
57 if ( providerReferenceTime.isValid() )
58 providerTime = providerReferenceTime.msecsTo( requestDateTime );
59 else
60 providerTime = time;
61
62 switch ( method )
63 {
65 return mTemporalCapabilities->datasetIndexClosestBeforeRelativeTime( groupIndex, providerTime );
66 break;
68 return mTemporalCapabilities->datasetIndexClosestFromRelativeTime( groupIndex, providerTime );
69 break;
70 }
71
72 return QgsMeshDatasetIndex();
73}
74
75QList<QgsMeshDatasetIndex> QgsMeshDatasetSourceInterface::datasetIndexInTimeInterval( const QDateTime &referenceTime, int groupIndex, qint64 time1, qint64 time2 ) const
76{
77 const QDateTime requestDateTime = referenceTime.addMSecs( time1 );
78 qint64 providerTime1;
79 qint64 providerTime2;
80 const QDateTime providerReferenceTime = mTemporalCapabilities->referenceTime();
81 if ( mTemporalCapabilities->referenceTime().isValid() )
82 {
83 providerTime1 = providerReferenceTime.msecsTo( requestDateTime );
84 providerTime2 = providerTime1 - time1 + time2;
85 }
86 else
87 {
88 providerTime1 = time1;
89 providerTime2 = time2;
90 }
91
92 QList<QgsMeshDatasetIndex> ret;
93 for ( int i = 0; i < datasetCount( groupIndex ); ++i )
94 {
95 QgsMeshDatasetIndex datasetIndex( groupIndex, i );
96 qint64 time = mTemporalCapabilities->datasetTime( datasetIndex );
97 if ( time >= providerTime1 && time <= providerTime2 )
98 ret.append( datasetIndex );
99 }
100
101 return ret;
102}
103
105 mTemporalCapabilities( std::make_unique<QgsMeshDataProviderTemporalCapabilities>() ) {}
106
108{
109 return datasetCount( index.group() );
110}
111
113{
114 return datasetGroupMetadata( index.group() );
115}
116
118 const QString &path,
119 const QgsMeshDatasetGroupMetadata &meta,
120 const QVector<QgsMeshDataBlock> &datasetValues,
121 const QVector<QgsMeshDataBlock> &datasetActive,
122 const QVector<double> &times )
123{
124 // Form DRIVER:filename
125 QString filename = path;
126 // ASCII dat supports face, edge and vertex datasets
127 QString driverName = QStringLiteral( "DAT" );
128 QStringList parts = path.split( ':' );
129 if ( parts.size() > 1 )
130 {
131 driverName = parts[0];
132 parts.removeFirst();
133 filename = parts.join( QString() );
134 }
135 return persistDatasetGroup( filename, driverName, meta, datasetValues, datasetActive, times );
136}
137
139{
140 if ( index < vertices.size() && index >= 0 )
141 return vertices[index];
142 return QgsMeshVertex();
143}
144
145QgsMeshFace QgsMesh::face( int index ) const
146{
147 if ( index < faces.size() && index >= 0 )
148 return faces[index];
149 return QgsMeshFace();
150}
151
152QgsMeshEdge QgsMesh::edge( int index ) const
153{
154 if ( index < edges.size() && index >= 0 )
155 return edges[index];
156 return QgsMeshEdge();
157}
158
160{
161 vertices.clear();
162 edges.clear();
163 faces.clear();
164}
165
166bool QgsMesh::compareFaces( const QgsMeshFace &face1, const QgsMeshFace &face2 )
167{
168 if ( face1.count() != face2.count() )
169 return false;
170
171 int startFace2 = 0;
172 for ( int i = 0; i < face2.count(); ++i )
173 if ( face2.at( i ) == face1.at( 0 ) )
174 {
175 startFace2 = i;
176 break;
177 }
178
179 for ( int i = 0; i < face1.count(); ++i )
180 if ( face1.at( i ) != face2.at( ( i + startFace2 ) % ( face2.count() ) ) )
181 return false;
182
183 return true;
184}
185
187{
188 switch ( type )
189 {
190 case ElementType::Vertex:
191 return !vertices.isEmpty();
192 case ElementType::Edge:
193 return !edges.isEmpty();
194 case ElementType::Face:
195 return !faces.isEmpty();
196 }
197 return false;
198}
199
201{
202 return vertices.size();
203}
204
206{
207 return faces.size();
208}
209
211{
212 return edges.size();
213}
214
216{
217 switch ( type )
218 {
219 case QgsMesh::ElementType::Vertex:
220 return vertexCount() != 0;
221 case QgsMesh::ElementType::Edge:
222 return edgeCount() != 0;
223 case QgsMesh::ElementType::Face:
224 return faceCount() != 0;
225 }
226 return false;
227}
Abstract base class for spatial data provider implementations.
virtual void reloadData()
Reloads the data from the source for providers with data caches to synchronize, changes in the data s...
Class for handling properties relating to a mesh data provider's temporal capabilities.
MatchingTemporalDatasetMethod
Method for selection of temporal mesh dataset from a range time.
@ FindClosestDatasetFromStartRangeTime
Finds the closest dataset which have its time before the requested start range time.
virtual QgsMeshDriverMetadata driverMetadata() const
Returns the mesh driver metadata of the provider.
QgsMeshDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
void setTemporalUnit(QgsUnitTypes::TemporalUnit unit)
Sets the temporal unit of the provider and reload data if it changes.
QgsMeshDataProvider(const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions, QgsDataProvider::ReadFlags flags=QgsDataProvider::ReadFlags())
Ctor.
virtual int vertexCount() const =0
Returns number of vertices in the native mesh.
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
virtual int edgeCount() const =0
Returns number of edges in the native mesh.
virtual int faceCount() const =0
Returns number of faces in the native mesh.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
int group() const
Returns a group index.
virtual QgsMeshDataBlock datasetValues(QgsMeshDatasetIndex index, int valueIndex, int count) const =0
Returns N vector/scalar values from the index from the dataset.
virtual int datasetCount(int groupIndex) const =0
Returns number of datasets loaded in the group.
virtual Q_DECL_DEPRECATED bool persistDatasetGroup(const QString &path, const QgsMeshDatasetGroupMetadata &meta, const QVector< QgsMeshDataBlock > &datasetValues, const QVector< QgsMeshDataBlock > &datasetActive, const QVector< double > &times)
Creates a new dataset group from a data and persists it into a destination path.
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
std::unique_ptr< QgsMeshDataProviderTemporalCapabilities > mTemporalCapabilities
QgsMeshDatasetIndex datasetIndexAtTime(const QDateTime &referenceTime, int groupIndex, qint64 time, QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod method) const
Returns the dataset index of the dataset in a specific dataset group at time from the reference time.
QList< QgsMeshDatasetIndex > datasetIndexInTimeInterval(const QDateTime &referenceTime, int groupIndex, qint64 time1, qint64 time2) const
Returns a list of dataset indexes of the dataset in a specific dataset group that are between time1 a...
Holds metadata about mesh driver.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
TemporalUnit
Temporal units.
Definition: qgsunittypes.h:150
QVector< int > QgsMeshFace
List of vertex indexes.
QPair< int, int > QgsMeshEdge
Edge is a straight line seqment between 2 points.
QgsPoint QgsMeshVertex
xyz coords of vertex
Setting options for creating vector data providers.
int vertexCount() const
Returns number of vertices.
QVector< QgsMeshVertex > vertices
QgsMeshFace face(int index) const
Returns a face at the index.
bool contains(const ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
QVector< QgsMeshFace > faces
static bool compareFaces(const QgsMeshFace &face1, const QgsMeshFace &face2)
Compare two faces, return true if they are equivalent : same indexes and same clock wise.
void clear()
Remove all vertices, edges and faces.
int faceCount() const
Returns number of faces.
ElementType
Defines type of mesh elements.
QgsMeshEdge edge(int index) const
Returns an edge at the index.
QgsMeshVertex vertex(int index) const
Returns a vertex at the index.
int edgeCount() const
Returns number of edge.
QVector< QgsMeshEdge > edges