QGIS API Documentation 3.41.0-Master (3440c17df1d)
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 "qgis.h"
19#include "qgsmeshdataprovider.h"
20#include "moc_qgsmeshdataprovider.cpp"
22#include "qgsthreadingutils.h"
23
26 : QgsDataProvider( uri, options, flags )
27{
28}
29
36
43
45{
47
49 mTemporalCapabilities->setTemporalUnit( unit );
50 if ( oldUnit != unit )
51 reloadData();
52}
53
60
62 const QDateTime &referenceTime,
63 int groupIndex, qint64 time,
65{
66 const QDateTime requestDateTime = referenceTime.addMSecs( time );
67 qint64 providerTime;
68 const QDateTime providerReferenceTime = mTemporalCapabilities->referenceTime();
69 if ( providerReferenceTime.isValid() )
70 providerTime = providerReferenceTime.msecsTo( requestDateTime );
71 else
72 providerTime = time;
73
74 switch ( method )
75 {
77 return mTemporalCapabilities->datasetIndexClosestBeforeRelativeTime( groupIndex, providerTime );
78 break;
80 return mTemporalCapabilities->datasetIndexClosestFromRelativeTime( groupIndex, providerTime );
81 break;
82 }
83
84 return QgsMeshDatasetIndex();
85}
86
87QList<QgsMeshDatasetIndex> QgsMeshDatasetSourceInterface::datasetIndexInTimeInterval( const QDateTime &referenceTime, int groupIndex, qint64 time1, qint64 time2 ) const
88{
89 const QDateTime requestDateTime = referenceTime.addMSecs( time1 );
90 qint64 providerTime1;
91 qint64 providerTime2;
92 const QDateTime providerReferenceTime = mTemporalCapabilities->referenceTime();
93 if ( mTemporalCapabilities->referenceTime().isValid() )
94 {
95 providerTime1 = providerReferenceTime.msecsTo( requestDateTime );
96 providerTime2 = providerTime1 - time1 + time2;
97 }
98 else
99 {
100 providerTime1 = time1;
101 providerTime2 = time2;
102 }
103
104 QList<QgsMeshDatasetIndex> ret;
105 for ( int i = 0; i < datasetCount( groupIndex ); ++i )
106 {
107 QgsMeshDatasetIndex datasetIndex( groupIndex, i );
108 qint64 time = mTemporalCapabilities->datasetTime( datasetIndex );
109 if ( time >= providerTime1 && time <= providerTime2 )
110 ret.append( datasetIndex );
111 }
112
113 return ret;
114}
115
118
120{
121 return datasetCount( index.group() );
122}
123
128
130 const QString &path,
131 const QgsMeshDatasetGroupMetadata &meta,
132 const QVector<QgsMeshDataBlock> &datasetValues,
133 const QVector<QgsMeshDataBlock> &datasetActive,
134 const QVector<double> &times )
135{
136 // Form DRIVER:filename
137 QString filename = path;
138 // ASCII dat supports face, edge and vertex datasets
139 QString driverName = QStringLiteral( "DAT" );
140 QStringList parts = path.split( ':' );
141 if ( parts.size() > 1 )
142 {
143 driverName = parts[0];
144 parts.removeFirst();
145 filename = parts.join( QString() );
146 }
147 return persistDatasetGroup( filename, driverName, meta, datasetValues, datasetActive, times );
148}
149
151{
152 if ( index < vertices.size() && index >= 0 )
153 return vertices[index];
154 return QgsMeshVertex();
155}
156
157QgsMeshFace QgsMesh::face( int index ) const
158{
159 if ( index < faces.size() && index >= 0 )
160 return faces[index];
161 return QgsMeshFace();
162}
163
164QgsMeshEdge QgsMesh::edge( int index ) const
165{
166 if ( index < edges.size() && index >= 0 )
167 return edges[index];
168 return QgsMeshEdge();
169}
170
172{
173 vertices.clear();
174 edges.clear();
175 faces.clear();
176}
177
178bool QgsMesh::compareFaces( const QgsMeshFace &face1, const QgsMeshFace &face2 )
179{
180 if ( face1.count() != face2.count() )
181 return false;
182
183 int startFace2 = 0;
184 for ( int i = 0; i < face2.count(); ++i )
185 if ( face2.at( i ) == face1.at( 0 ) )
186 {
187 startFace2 = i;
188 break;
189 }
190
191 for ( int i = 0; i < face1.count(); ++i )
192 if ( face1.at( i ) != face2.at( ( i + startFace2 ) % ( face2.count() ) ) )
193 return false;
194
195 return true;
196}
197
199{
200 switch ( type )
201 {
203 return !vertices.isEmpty();
205 return !edges.isEmpty();
207 return !faces.isEmpty();
208 }
209 return false;
210}
211
213{
214 return vertices.size();
215}
216
218{
219 return faces.size();
220}
221
223{
224 return edges.size();
225}
226
228{
229 switch ( type )
230 {
232 return vertexCount() != 0;
234 return edgeCount() != 0;
236 return faceCount() != 0;
237 }
238 return false;
239}
TemporalUnit
Temporal units.
Definition qgis.h:4823
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
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.
Qgis::TemporalUnit temporalUnit() const
Returns the temporal unit used to read data by the data provider.
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.
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.
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
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.
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