QGIS API Documentation 4.3.0-Master (91d4a333d5d)
Loading...
Searching...
No Matches
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 "qgsmeshdataprovider.h"
19
20#include "qgis.h"
22#include "qgsthreadingutils.h"
23
24#include <QString>
25
26#include "moc_qgsmeshdataprovider.cpp"
27
28using namespace Qt::StringLiterals;
29
33
40
47
49{
51
52 const Qgis::TemporalUnit oldUnit = mTemporalCapabilities->temporalUnit();
53 mTemporalCapabilities->setTemporalUnit( unit );
54 if ( oldUnit != unit )
55 reloadData();
56}
57
64
66 const QDateTime &referenceTime, int groupIndex, qint64 time, QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod method
67) const
68{
69 const QDateTime requestDateTime = referenceTime.addMSecs( time );
70 qint64 providerTime;
71 const QDateTime providerReferenceTime = mTemporalCapabilities->referenceTime();
72 if ( providerReferenceTime.isValid() )
73 providerTime = providerReferenceTime.msecsTo( requestDateTime );
74 else
75 providerTime = time;
76
77 switch ( method )
78 {
80 return mTemporalCapabilities->datasetIndexClosestBeforeRelativeTime( groupIndex, providerTime );
81 break;
83 return mTemporalCapabilities->datasetIndexClosestFromRelativeTime( groupIndex, providerTime );
84 break;
85 }
86
87 return QgsMeshDatasetIndex();
88}
89
90QList<QgsMeshDatasetIndex> QgsMeshDatasetSourceInterface::datasetIndexInTimeInterval( const QDateTime &referenceTime, int groupIndex, qint64 time1, qint64 time2 ) const
91{
92 const QDateTime requestDateTime = referenceTime.addMSecs( time1 );
93 qint64 providerTime1;
94 qint64 providerTime2;
95 const QDateTime providerReferenceTime = mTemporalCapabilities->referenceTime();
96 if ( mTemporalCapabilities->referenceTime().isValid() )
97 {
98 providerTime1 = providerReferenceTime.msecsTo( requestDateTime );
99 providerTime2 = providerTime1 - time1 + time2;
100 }
101 else
102 {
103 providerTime1 = time1;
104 providerTime2 = time2;
105 }
106
107 QList<QgsMeshDatasetIndex> ret;
108 for ( int i = 0; i < datasetCount( groupIndex ); ++i )
109 {
110 QgsMeshDatasetIndex datasetIndex( groupIndex, i );
111 qint64 time = mTemporalCapabilities->datasetTime( datasetIndex );
112 if ( time >= providerTime1 && time <= providerTime2 )
113 ret.append( datasetIndex );
114 }
115
116 return ret;
117}
118
122
124{
125 return datasetCount( index.group() );
126}
127
132
134 const QString &path, const QgsMeshDatasetGroupMetadata &meta, const QVector<QgsMeshDataBlock> &datasetValues, const QVector<QgsMeshDataBlock> &datasetActive, const QVector<double> &times
135)
136{
137 // Form DRIVER:filename
138 QString filename = path;
139 // ASCII dat supports face, edge and vertex datasets
140 QString driverName = u"DAT"_s;
141 QStringList parts = path.split( ':' );
142 if ( parts.size() > 1 )
143 {
144 driverName = parts[0];
145 parts.removeFirst();
146 filename = parts.join( QString() );
147 }
148 return persistDatasetGroup( filename, driverName, meta, datasetValues, datasetActive, times );
149}
150
152{
153 if ( index < vertices.size() && index >= 0 )
154 return vertices[index];
155 return QgsMeshVertex();
156}
157
158QgsMeshFace QgsMesh::face( int index ) const
159{
160 if ( index < faces.size() && index >= 0 )
161 return faces[index];
162 return QgsMeshFace();
163}
164
165QgsMeshEdge QgsMesh::edge( int index ) const
166{
167 if ( index < edges.size() && index >= 0 )
168 return edges[index];
169 return QgsMeshEdge();
170}
171
173{
174 vertices.clear();
175 edges.clear();
176 faces.clear();
177}
178
179bool QgsMesh::compareFaces( const QgsMeshFace &face1, const QgsMeshFace &face2 )
180{
181 if ( face1.count() != face2.count() )
182 return false;
183
184 int startFace2 = 0;
185 for ( int i = 0; i < face2.count(); ++i )
186 if ( face2.at( i ) == face1.at( 0 ) )
187 {
188 startFace2 = i;
189 break;
190 }
191
192 for ( int i = 0; i < face1.count(); ++i )
193 if ( face1.at( i ) != face2.at( ( i + startFace2 ) % ( face2.count() ) ) )
194 return false;
195
196 return true;
197}
198
199void QgsMesh::calculateZMinMax() const
200{
201 mZMin = std::numeric_limits<double>::max();
202 mZMax = -std::numeric_limits<double>::max();
203
204 for ( qsizetype i = 0; i < vertices.size(); ++i )
205 {
206 const double z = vertices[i].z();
207 if ( std::isnan( z ) )
208 continue;
209 if ( z < mZMin )
210 mZMin = z;
211 if ( z > mZMax )
212 mZMax = z;
213 }
214}
215
217{
218 if ( !zMinMaxIsValid() )
219 calculateZMinMax();
220
221 return mZMin;
222}
223
225{
226 if ( !zMinMaxIsValid() )
227 calculateZMinMax();
228
229 return mZMax;
230}
231
233{
234 mZMin = std::numeric_limits<double>::quiet_NaN();
235 mZMax = std::numeric_limits<double>::quiet_NaN();
236}
237
238bool QgsMesh::zMinMaxIsValid() const
239{
240 return !std::isnan( mZMin ) && !std::isnan( mZMax );
241}
242
244{
245 switch ( type )
246 {
248 return !vertices.isEmpty();
250 return !edges.isEmpty();
252 return !faces.isEmpty();
253 }
254 return false;
255}
256
258{
259 return vertices.size();
260}
261
263{
264 return faces.size();
265}
266
268{
269 return edges.size();
270}
271
273{
274 switch ( type )
275 {
277 return vertexCount() != 0;
279 return edgeCount() != 0;
281 return faceCount() != 0;
282 }
283 return false;
284}
TemporalUnit
Temporal units.
Definition qgis.h:5746
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:532
virtual Qgis::DataProviderFlags flags() const
Returns the generic data provider flags.
QgsDataProvider(const QString &uri=QString(), const QgsDataProvider::ProviderOptions &providerOptions=QgsDataProvider::ProviderOptions(), Qgis::DataProviderReadFlags flags=Qgis::DataProviderReadFlags())
Create a new dataprovider with the specified in the uri.
QgsDataSourceUri uri() const
Gets the data source specification.
virtual void reloadData()
Reloads the data from the source for providers with data caches to synchronize, changes in the data s...
Handles properties relating to a mesh data provider's temporal capabilities.
MatchingTemporalDatasetMethod
Method for selection of temporal mesh dataset from a range time.
@ FindClosestDatasetBeforeStartRangeTime
Finds the closest dataset which have its time before the requested start range time.
@ FindClosestDatasetFromStartRangeTime
Finds the closest dataset before or after the requested start range time.
virtual QgsMeshDriverMetadata driverMetadata() const
Returns the mesh driver metadata of the provider.
void setTemporalUnit(Qgis::TemporalUnit unit)
Sets the temporal unit of the provider and reload data if it changes.
QgsMeshDataProvider(const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions, Qgis::DataProviderReadFlags=Qgis::DataProviderReadFlags())
Ctor.
QgsMeshDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
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.
A collection of dataset group metadata such as whether the data is vector or scalar,...
An 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 drivers.
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
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Setting options for creating vector data providers.
double maximumElevation() const
Returns the maximum elevation value of all vertices of the mesh.
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.
double minimumElevation() const
Returns the minimum elevation value of all vertices of the mesh.
QgsMeshVertex vertex(int index) const
Returns a vertex at the index.
void invalidateZMinMax()
Invalidates the minimum and maximum elevation values, therefoe when querying zMinimum() or zMaximum()...
int edgeCount() const
Returns number of edge.
QVector< QgsMeshEdge > edges