QGIS API Documentation  3.4.3-Madeira (2f64a3c)
qgsrasterminmaxorigin.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterminmaxorigin.h - Origin of min/max values
3  --------------------------------------
4  Date : Dec 2016
5  Copyright : (C) 2016 by Even Rouault
6  email : even.rouault at spatialys.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 "qgsrasterminmaxorigin.h"
19 #include "qgssettings.h"
20 
21 #include <QDomDocument>
22 #include <QDomElement>
23 
25  : mCumulativeCutLower( CUMULATIVE_CUT_LOWER )
26  , mCumulativeCutUpper( CUMULATIVE_CUT_UPPER )
27  , mStdDevFactor( DEFAULT_STDDEV_FACTOR )
28 {
29  QgsSettings mySettings;
30  mCumulativeCutLower = mySettings.value( QStringLiteral( "Raster/cumulativeCutLower" ), CUMULATIVE_CUT_LOWER ).toDouble();
31  mCumulativeCutUpper = mySettings.value( QStringLiteral( "Raster/cumulativeCutUpper" ), CUMULATIVE_CUT_UPPER ).toDouble();
32  mStdDevFactor = mySettings.value( QStringLiteral( "Raster/defaultStandardDeviation" ), DEFAULT_STDDEV_FACTOR ).toDouble();
33 }
34 
36 {
37  return mLimits == other.mLimits &&
38  mExtent == other.mExtent &&
39  mAccuracy == other.mAccuracy &&
40  std::fabs( mCumulativeCutLower - other.mCumulativeCutLower ) < 1e-5 &&
41  std::fabs( mCumulativeCutUpper - other.mCumulativeCutUpper ) < 1e-5 &&
42  std::fabs( mStdDevFactor - other.mStdDevFactor ) < 1e-5;
43 }
44 
46 {
47  switch ( limits )
48  {
49  case MinMax:
50  return QStringLiteral( "MinMax" );
51  case StdDev:
52  return QStringLiteral( "StdDev" );
53  case CumulativeCut:
54  return QStringLiteral( "CumulativeCut" );
55  default:
56  break;
57  }
58  return QStringLiteral( "None" );
59 }
60 
62 {
63  if ( limits == QLatin1String( "MinMax" ) )
64  {
65  return MinMax;
66  }
67  else if ( limits == QLatin1String( "StdDev" ) )
68  {
69  return StdDev;
70  }
71  else if ( limits == QLatin1String( "CumulativeCut" ) )
72  {
73  return CumulativeCut;
74  }
75  return None;
76 }
77 
79 {
80  switch ( minMaxExtent )
81  {
82  case WholeRaster:
83  return QStringLiteral( "WholeRaster" );
84  case CurrentCanvas:
85  return QStringLiteral( "CurrentCanvas" );
86  case UpdatedCanvas:
87  return QStringLiteral( "UpdatedCanvas" );
88  }
89  return QStringLiteral( "WholeRaster" );
90 }
91 
93 {
94  if ( extent == QLatin1String( "WholeRaster" ) )
95  {
96  return WholeRaster;
97  }
98  else if ( extent == QLatin1String( "CurrentCanvas" ) )
99  {
100  return CurrentCanvas;
101  }
102  else if ( extent == QLatin1String( "UpdatedCanvas" ) )
103  {
104  return UpdatedCanvas;
105  }
106  else
107  {
108  return WholeRaster;
109  }
110 }
111 
113 {
114  if ( accuracy == Exact )
115  return QStringLiteral( "Exact" );
116  return QStringLiteral( "Estimated" );
117 }
118 
120 {
121  if ( accuracy == QLatin1String( "Exact" ) )
122  return Exact;
123  return Estimated;
124 }
125 
126 void QgsRasterMinMaxOrigin::writeXml( QDomDocument &doc, QDomElement &parentElem ) const
127 {
128  // limits
129  QDomElement limitsElem = doc.createElement( QStringLiteral( "limits" ) );
130  QDomText limitsText = doc.createTextNode( limitsString( mLimits ) );
131  limitsElem.appendChild( limitsText );
132  parentElem.appendChild( limitsElem );
133 
134  // extent
135  QDomElement extentElem = doc.createElement( QStringLiteral( "extent" ) );
136  QDomText extentText = doc.createTextNode( extentString( mExtent ) );
137  extentElem.appendChild( extentText );
138  parentElem.appendChild( extentElem );
139 
140  // statAccuracy
141  QDomElement statAccuracyElem = doc.createElement( QStringLiteral( "statAccuracy" ) );
142  QDomText statAccuracyText = doc.createTextNode( statAccuracyString( mAccuracy ) );
143  statAccuracyElem.appendChild( statAccuracyText );
144  parentElem.appendChild( statAccuracyElem );
145 
146  // mCumulativeCutLower
147  QDomElement cumulativeCutLowerElem = doc.createElement( QStringLiteral( "cumulativeCutLower" ) );
148  QDomText cumulativeCutLowerText = doc.createTextNode( QString::number( mCumulativeCutLower ) );
149  cumulativeCutLowerElem.appendChild( cumulativeCutLowerText );
150  parentElem.appendChild( cumulativeCutLowerElem );
151 
152  // mCumulativeCutUpper
153  QDomElement cumulativeCutUpperElem = doc.createElement( QStringLiteral( "cumulativeCutUpper" ) );
154  QDomText cumulativeCutUpperText = doc.createTextNode( QString::number( mCumulativeCutUpper ) );
155  cumulativeCutUpperElem.appendChild( cumulativeCutUpperText );
156  parentElem.appendChild( cumulativeCutUpperElem );
157 
158  // mCumulativeCutUpper
159  QDomElement stdDevFactorElem = doc.createElement( QStringLiteral( "stdDevFactor" ) );
160  QDomText stdDevFactorText = doc.createTextNode( QString::number( mStdDevFactor ) );
161  stdDevFactorElem.appendChild( stdDevFactorText );
162  parentElem.appendChild( stdDevFactorElem );
163 }
164 
165 void QgsRasterMinMaxOrigin::readXml( const QDomElement &elem )
166 {
167  QDomElement limitsElem = elem.firstChildElement( QStringLiteral( "limits" ) );
168  if ( !limitsElem.isNull() )
169  {
170  mLimits = limitsFromString( limitsElem.text() );
171  }
172 
173  QDomElement extentElem = elem.firstChildElement( QStringLiteral( "extent" ) );
174  if ( !extentElem.isNull() )
175  {
176  mExtent = extentFromString( extentElem.text() );
177  }
178 
179  QDomElement statAccuracyElem = elem.firstChildElement( QStringLiteral( "statAccuracy" ) );
180  if ( !statAccuracyElem.isNull() )
181  {
182  mAccuracy = statAccuracyFromString( statAccuracyElem.text() );
183  }
184 
185  QDomElement cumulativeCutLowerElem = elem.firstChildElement( QStringLiteral( "cumulativeCutLower" ) );
186  if ( !cumulativeCutLowerElem.isNull() )
187  {
188  mCumulativeCutLower = cumulativeCutLowerElem.text().toDouble();
189  }
190 
191  QDomElement cumulativeCutUpperElem = elem.firstChildElement( QStringLiteral( "cumulativeCutUpper" ) );
192  if ( !cumulativeCutUpperElem.isNull() )
193  {
194  mCumulativeCutUpper = cumulativeCutUpperElem.text().toDouble();
195  }
196 
197  QDomElement stdDevFactorElem = elem.firstChildElement( QStringLiteral( "stdDevFactor" ) );
198  if ( !stdDevFactorElem.isNull() )
199  {
200  mStdDevFactor = stdDevFactorElem.text().toDouble();
201  }
202 }
QgsRasterMinMaxOrigin::Limits limits() const
Returns the raster limits.
QgsRasterMinMaxOrigin::Extent extent() const
Returns the raster extent.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QgsRasterMinMaxOrigin()
Default constructor.
Extent
This enumerator describes the extent used to compute min/max values.
static Limits limitsFromString(const QString &limits)
Deserialize Limits.
StatAccuracy
This enumerator describes the accuracy used to compute statistics.
static QgsRasterMinMaxOrigin::Extent extentFromString(const QString &extent)
Deserialize Extent.
Current extent of the canvas (at the time of computation) is used to compute statistics.
This class describes the origin of min/max values.
bool operator==(const QgsRasterMinMaxOrigin &other) const
Equality operator.
void readXml(const QDomElement &elem)
Deserialize object.
Constantly updated extent of the canvas is used to compute statistics.
static constexpr double DEFAULT_STDDEV_FACTOR
Default standard deviation factor.
Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ].
static constexpr double CUMULATIVE_CUT_UPPER
Default cumulative cut upper limit.
static constexpr double CUMULATIVE_CUT_LOWER
Default cumulative cut lower limit.
Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]...
static QString limitsString(Limits limits)
Returns a string to serialize Limits.
static QString extentString(QgsRasterMinMaxOrigin::Extent extent)
Returns a string to serialize Extent.
Limits
This enumerator describes the limits used to compute min/max values.
Whole raster is used to compute statistics.
static QString statAccuracyString(QgsRasterMinMaxOrigin::StatAccuracy accuracy)
Returns a string to serialize StatAccuracy.
static QgsRasterMinMaxOrigin::StatAccuracy statAccuracyFromString(const QString &accuracy)
Deserialize StatAccuracy.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Serialize object.