QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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( uri, options ), mTemporalCapabilities( qgis::make_unique<QgsMeshDataProviderTemporalCapabilities>() )
25 {
26 }
27 
29 {
30  return mTemporalCapabilities.get();
31 }
32 
34 {
35  return mTemporalCapabilities.get();
36 }
37 
39 {
40  QgsUnitTypes::TemporalUnit oldUnit = mTemporalCapabilities->temporalUnit();
41  mTemporalCapabilities->setTemporalUnit( unit );
42  if ( oldUnit != unit )
43  reloadData();
44 }
45 
47 {
48  return datasetCount( index.group() );
49 }
50 
52 {
53  return datasetGroupMetadata( index.group() );
54 }
55 
57  const QString &path,
58  const QgsMeshDatasetGroupMetadata &meta,
59  const QVector<QgsMeshDataBlock> &datasetValues,
60  const QVector<QgsMeshDataBlock> &datasetActive,
61  const QVector<double> &times )
62 {
63  // Form DRIVER:filename
64  QString filename = path;
65  // ASCII dat supports face, edge and vertex datasets
66  QString driverName = QStringLiteral( "DAT" );
67  QStringList parts = path.split( ':' );
68  if ( parts.size() > 1 )
69  {
70  driverName = parts[0];
71  parts.removeFirst();
72  filename = parts.join( QString() );
73  }
74  return persistDatasetGroup( filename, driverName, meta, datasetValues, datasetActive, times );
75 }
76 
77 QgsMeshVertex QgsMesh::vertex( int index ) const
78 {
79  if ( index < vertices.size() && index >= 0 )
80  return vertices[index];
81  return QgsMeshVertex();
82 }
83 
84 QgsMeshFace QgsMesh::face( int index ) const
85 {
86  if ( index < faces.size() && index >= 0 )
87  return faces[index];
88  return QgsMeshFace();
89 }
90 
91 QgsMeshEdge QgsMesh::edge( int index ) const
92 {
93  if ( index < edges.size() && index >= 0 )
94  return edges[index];
95  return QgsMeshEdge();
96 }
97 
99 {
100  vertices.clear();
101  edges.clear();
102  faces.clear();
103 }
104 
105 bool QgsMesh::contains( const QgsMesh::ElementType &type ) const
106 {
107  switch ( type )
108  {
109  case ElementType::Vertex:
110  return !vertices.isEmpty();
111  case ElementType::Edge:
112  return !edges.isEmpty();
113  case ElementType::Face:
114  return !faces.isEmpty();
115  }
116  return false;
117 }
118 
120 {
121  return vertices.size();
122 }
123 
125 {
126  return faces.size();
127 }
128 
130 {
131  return edges.size();
132 }
133 
135 {
136  switch ( type )
137  {
138  case QgsMesh::ElementType::Vertex:
139  return vertexCount() != 0;
140  case QgsMesh::ElementType::Edge:
141  return edgeCount() != 0;
143  return faceCount() != 0;
144  }
145  return false;
146 }
QgsMeshDatasetSourceInterface::datasetCount
virtual int datasetCount(int groupIndex) const =0
Returns number of datasets loaded in the group.
Face
struct Face_t Face
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:104
QgsDataProvider
Definition: qgsdataprovider.h:41
qgsrectangle.h
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
QgsMeshVertex
QgsPoint QgsMeshVertex
xyz coords of vertex
Definition: qgsmeshdataprovider.h:35
QgsMeshDataProviderTemporalCapabilities
Definition: qgsmeshdataprovidertemporalcapabilities.h:33
qgis.h
QgsMeshDataSourceInterface::contains
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
Definition: qgsmeshdataprovider.cpp:134
QgsUnitTypes::TemporalUnit
TemporalUnit
Temporal units.
Definition: qgsunittypes.h:149
QgsMesh::edges
QVector< QgsMeshEdge > edges
Definition: qgsmeshdataprovider.h:106
QgsMeshDataProvider::QgsMeshDataProvider
QgsMeshDataProvider(const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions)
Ctor.
Definition: qgsmeshdataprovider.cpp:23
QgsMeshDataProvider::temporalCapabilities
QgsMeshDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
Definition: qgsmeshdataprovider.cpp:28
QgsMeshDatasetSourceInterface::datasetValues
virtual QgsMeshDataBlock datasetValues(QgsMeshDatasetIndex index, int valueIndex, int count) const =0
Returns N vector/scalar values from the index from the dataset.
QgsDataProvider::reloadData
virtual void reloadData()
Reloads the data from the source by calling reloadProviderData() implemented by providers with data c...
Definition: qgsdataprovider.cpp:38
QgsMesh::faceCount
int faceCount() const
Returns number of faces.
Definition: qgsmeshdataprovider.cpp:124
QgsMeshDatasetIndex::group
int group() const
Returns a group index.
Definition: qgsmeshdataset.cpp:26
QgsMesh::vertexCount
int vertexCount() const
Returns number of vertices.
Definition: qgsmeshdataprovider.cpp:119
QgsMesh::ElementType
ElementType
Defines type of mesh elements.
Definition: qgsmeshdataprovider.h:64
QgsMesh::faces
QVector< QgsMeshFace > faces
Definition: qgsmeshdataprovider.h:107
QgsMesh::edgeCount
int edgeCount() const
Returns number of edge.
Definition: qgsmeshdataprovider.cpp:129
QgsMesh::edge
QgsMeshEdge edge(int index) const
Returns an edge at the index.
Definition: qgsmeshdataprovider.cpp:91
QgsMeshDatasetIndex
Definition: qgsmeshdataset.h:45
QgsMeshDatasetSourceInterface::persistDatasetGroup
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.
Definition: qgsmeshdataprovider.cpp:56
QgsMeshDataProvider::setTemporalUnit
void setTemporalUnit(QgsUnitTypes::TemporalUnit unit)
Sets the temporal unit of the provider and reload data if it changes.
Definition: qgsmeshdataprovider.cpp:38
QgsMesh::face
QgsMeshFace face(int index) const
Returns a face at the index.
Definition: qgsmeshdataprovider.cpp:84
QgsMeshDataSourceInterface::edgeCount
virtual int edgeCount() const =0
Returns number of edges in the native mesh.
QgsMeshDataSourceInterface::vertexCount
virtual int vertexCount() const =0
Returns number of vertices in the native mesh.
QgsMeshFace
QVector< int > QgsMeshFace
List of vertex indexes.
Definition: qgsmeshdataprovider.h:41
QgsMesh::clear
void clear()
Remove all vertices, edges and faces.
Definition: qgsmeshdataprovider.cpp:98
QgsMeshDataSourceInterface::faceCount
virtual int faceCount() const =0
Returns number of faces in the native mesh.
QgsMesh::contains
bool contains(const ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
Definition: qgsmeshdataprovider.cpp:105
QgsMeshDatasetGroupMetadata
Definition: qgsmeshdataset.h:348
QgsMeshEdge
QPair< int, int > QgsMeshEdge
Edge is a straight line seqment between 2 points.
Definition: qgsmeshdataprovider.h:48
QgsMesh::vertices
QVector< QgsMeshVertex > vertices
Definition: qgsmeshdataprovider.h:105
qgsmeshdataprovidertemporalcapabilities.h
QgsMesh::vertex
QgsMeshVertex vertex(int index) const
Returns a vertex at the index.
Definition: qgsmeshdataprovider.cpp:77
qgsmeshdataprovider.h
QgsMeshDatasetSourceInterface::datasetGroupMetadata
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.