QGIS API Documentation  3.4.3-Madeira (2f64a3c)
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 #include "qgsrectangle.h"
20 #include "qgis.h"
21 
22 
23 
25  : mGroupIndex( group ), mDatasetIndex( dataset )
26 {}
27 
29 {
30  return mGroupIndex;
31 }
32 
34 {
35  return mDatasetIndex;
36 }
37 
39 {
40  return ( group() > -1 ) && ( dataset() > -1 );
41 }
42 
44 {
45  if ( isValid() && other.isValid() )
46  return other.group() == group() && other.dataset() == dataset();
47  else
48  return isValid() == other.isValid();
49 }
50 
52 {
53  return !( operator==( other ) );
54 }
55 
57  : QgsDataProvider( uri, options )
58 {
59 }
60 
61 
63 {
64  QgsRectangle rec;
65  rec.setMinimal();
66  for ( int i = 0; i < vertexCount(); ++i )
67  {
68  QgsMeshVertex v = vertex( i );
69  rec.setXMinimum( std::min( rec.xMinimum(), v.x() ) );
70  rec.setYMinimum( std::min( rec.yMinimum(), v.y() ) );
71  rec.setXMaximum( std::max( rec.xMaximum(), v.x() ) );
72  rec.setYMaximum( std::max( rec.yMaximum(), v.y() ) );
73  }
74  return rec;
75 
76 }
77 
79  : mX( x ), mY( y )
80 {}
81 
83  : mX( scalar )
84 {}
85 
87 {
88  if ( std::isnan( mY ) )
89  {
90  return mX;
91  }
92  else if ( std::isnan( mX ) )
93  {
94  return std::numeric_limits<double>::quiet_NaN();
95  }
96  else
97  {
98  return std::sqrt( ( mX ) * ( mX ) + ( mY ) * ( mY ) );
99  }
100 }
101 
103 {
104  setX( scalar );
105 }
106 
108 {
109  mX = x;
110 }
111 
113 {
114  mY = y;
115 }
116 
118 {
119  return mX;
120 }
121 
123 {
124  return mY;
125 }
126 
128 {
129  bool equal = std::isnan( mX ) == std::isnan( other.x() );
130  equal &= std::isnan( mY ) == std::isnan( other.y() );
131 
132  if ( equal )
133  {
134  if ( std::isnan( mY ) )
135  {
136  equal &= qgsDoubleNear( other.x(), mX, 1E-8 );
137  }
138  else
139  {
140  equal &= qgsDoubleNear( other.x(), mX, 1E-8 );
141  equal &= qgsDoubleNear( other.y(), mY, 1E-8 );
142  }
143  }
144  return equal;
145 }
146 
148  const QString &name,
149  bool isScalar,
150  bool isOnVertices,
151  const QMap<QString, QString> &extraOptions )
152  : mName( name )
153  , mIsScalar( isScalar )
154  , mIsOnVertices( isOnVertices )
155  , mExtraOptions( extraOptions )
156 {
157 }
158 
159 QMap<QString, QString> QgsMeshDatasetGroupMetadata::extraOptions() const
160 {
161  return mExtraOptions;
162 }
163 
165 {
166  return !mIsScalar;
167 }
168 
170 {
171  return mIsScalar;
172 }
173 
174 
175 
177 {
178  return mName;
179 }
180 
182 {
183  return ( mIsOnVertices ) ? DataType::DataOnVertices : DataType::DataOnFaces;
184 }
185 
187 {
188  return datasetCount( index.group() );
189 }
190 
192 {
193  return datasetGroupMetadata( index.group() );
194 }
195 
197  bool isValid )
198  : mTime( time )
199  , mIsValid( isValid )
200 {
201 }
202 
204 {
205  return mTime;
206 }
207 
209 {
210  return mIsValid;
211 }
bool operator==(const QgsMeshDatasetValue &other) const
A rectangle specified with double values.
Definition: qgsrectangle.h:40
double y
Definition: qgspoint.h:42
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:150
void set(double scalar)
Sets scalar value.
QgsMeshDatasetValue()=default
Default Ctor, initialize to NaN.
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:134
QString name() const
Returns name of the dataset group.
int dataset() const
Returns a dataset index within group()
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:278
virtual int datasetCount(int groupIndex) const =0
Returns number of datasets loaded in the group.
QgsMeshDatasetIndex(int group=-1, int dataset=-1)
Creates an index. -1 represents invalid group/dataset.
virtual int vertexCount() const =0
Returns number of vertices in the native mesh.
QgsMeshDatasetGroupMetadata()=default
Constructs an empty metadata object.
Abstract base class for spatial data provider implementations.
void setY(double y)
Sets Y value.
QgsMeshDataProvider(const QString &uri, const QgsDataProvider::ProviderOptions &options)
Ctor.
int group() const
Returns a group index.
bool operator!=(const QgsMeshDatasetIndex &other) const
Inequality operator.
QgsRectangle extent() const override
Returns the extent of the layer.
double y() const
Returns y value.
QgsMeshDatasetMetadata()=default
Constructs an empty metadata object.
DataType dataType() const
Returns whether dataset group data is defined on vertices or faces.
DataType
Location of where data is specified for datasets in the dataset group.
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:139
bool operator==(const QgsMeshDatasetIndex &other) const
Equality operator.
double scalar() const
Returns magnitude of vector for vector data or scalar value for scalar data.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
bool isValid() const
Returns whether dataset is valid.
bool isScalar() const
Returns whether dataset group has scalar data.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:176
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:161
virtual QgsMeshVertex vertex(int index) const =0
Returns the mesh vertex at index.
Setting options for creating vector data providers.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:144
QMap< QString, QString > extraOptions() const
Returns extra metadata options, for example description.
bool isVector() const
Returns whether dataset group has vector data.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:166
bool isValid() const
Returns whether index is valid, ie at least groups is set.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:171
double time() const
Returns the time value for this dataset.
QgsMeshDatasetValue represents single dataset value.
void setX(double x)
Sets X value.
double x() const
Returns x value.
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:129
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
double x
Definition: qgspoint.h:41