QGIS API Documentation  3.2.0-Bonn (bc43194)
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 "qgis.h"
20 
22  : QgsDataProvider( uri, options )
23 {
24 }
25 
26 
28 {
29  QgsRectangle rec;
30  rec.setMinimal();
31  for ( int i = 0; i < vertexCount(); ++i )
32  {
33  QgsMeshVertex v = vertex( i );
34  rec.setXMinimum( std::min( rec.xMinimum(), v.x() ) );
35  rec.setYMinimum( std::min( rec.yMinimum(), v.y() ) );
36  rec.setXMaximum( std::max( rec.xMaximum(), v.x() ) );
37  rec.setYMaximum( std::max( rec.yMaximum(), v.y() ) );
38  }
39  return rec;
40 
41 }
42 
44  : mX( x ), mY( y )
45 {}
46 
48  : mX( scalar )
49 {}
50 
52 {
53  if ( std::isnan( mY ) )
54  {
55  return mX;
56  }
57  else if ( std::isnan( mX ) )
58  {
59  return std::numeric_limits<double>::quiet_NaN();
60  }
61  else
62  {
63  return std::sqrt( ( mX ) * ( mX ) + ( mY ) * ( mY ) );
64  }
65 }
66 
68 {
69  setX( scalar );
70 }
71 
73 {
74  mX = x;
75 }
76 
78 {
79  mY = y;
80 }
81 
82 double QgsMeshDatasetValue::x() const
83 {
84  return mX;
85 }
86 
87 double QgsMeshDatasetValue::y() const
88 {
89  return mY;
90 }
91 
93 {
94  bool equal = std::isnan( mX ) == std::isnan( other.x() );
95  equal &= std::isnan( mY ) == std::isnan( other.y() );
96 
97  if ( equal )
98  {
99  if ( std::isnan( mY ) )
100  {
101  equal &= qgsDoubleNear( other.x(), mX, 1E-8 );
102  }
103  else
104  {
105  equal &= qgsDoubleNear( other.x(), mX, 1E-8 );
106  equal &= qgsDoubleNear( other.y(), mY, 1E-8 );
107  }
108  }
109  return equal;
110 }
111 
113  bool isScalar,
114  bool isValid,
115  bool isOnVertices,
116  const QMap<QString, QString> &extraOptions )
117  : mIsScalar( isScalar )
118  , mIsValid( isValid )
119  , mIsOnVertices( isOnVertices )
120  , mExtraOptions( extraOptions )
121 {
122 }
123 
124 QMap<QString, QString> QgsMeshDatasetMetadata::extraOptions() const
125 {
126  return mExtraOptions;
127 }
128 
130 {
131  return !mIsScalar;
132 }
133 
135 {
136  return mIsScalar;
137 }
138 
140 {
141  return mIsValid;
142 }
143 
144 
146 {
147  return mIsOnVertices;
148 }
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
bool isScalar() const
Returns whether dataset has scalar data.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:251
virtual int vertexCount() const =0
Returns number of vertices in the native mesh.
bool isVector() const
Returns whether dataset has vector data.
bool isOnVertices() const
Returns whether dataset data is defined on vertices.
Abstract base class for spatial data provider implementations.
void setY(double y)
Sets Y value.
QgsMeshDataProvider(const QString &uri, const QgsDataProvider::ProviderOptions &options)
Ctor.
QgsRectangle extent() const override
Returns the extent of the layer.
double y() const
Returns y value.
QgsMeshDatasetMetadata()=default
Constructs an empty metadata object.
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:139
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.
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.
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:144
QMap< QString, QString > extraOptions() const
Returns extra metadata options Usually including name, description or time variable.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:166
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:171
QgsMeshDatasetValue represents single mesh 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
double x
Definition: qgspoint.h:41