QGIS API Documentation 4.1.0-Master (376402f9aeb)
Loading...
Searching...
No Matches
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
19
20#include <cmath>
21
24#include "qgssettingstree.h"
25
26#include <QDomDocument>
27#include <QDomElement>
28#include <QString>
29
30using namespace Qt::StringLiterals;
31
33 u"cumulative-cut-lower"_s,
35 CUMULATIVE_CUT_LOWER,
36 u"Default lower cumulative cut value (a fraction between 0 and 1) used when computing raster min/max values via the cumulative count cut method."_s,
38 0.0,
39 1.0
40);
42 u"cumulative-cut-upper"_s,
44 CUMULATIVE_CUT_UPPER,
45 u"Default upper cumulative cut value (a fraction between 0 and 1) used when computing raster min/max values via the cumulative count cut method."_s,
47 0.0,
48 1.0
49);
50
52 : mCumulativeCutLower( CUMULATIVE_CUT_LOWER )
53 , mCumulativeCutUpper( CUMULATIVE_CUT_UPPER )
54 , mStdDevFactor( DEFAULT_STDDEV_FACTOR )
55{
56 mCumulativeCutLower = settingsCumulativeCutLower->value();
57 mCumulativeCutUpper = settingsCumulativeCutUpper->value();
59}
60
62{
63 return mLimits == other.mLimits
64 && mExtent == other.mExtent
65 && mAccuracy == other.mAccuracy
66 && std::fabs( mCumulativeCutLower - other.mCumulativeCutLower ) < 1e-5
67 && std::fabs( mCumulativeCutUpper - other.mCumulativeCutUpper ) < 1e-5
68 && std::fabs( mStdDevFactor - other.mStdDevFactor ) < 1e-5;
69}
70
72{
73 switch ( limits )
74 {
76 return u"MinMax"_s;
78 return u"StdDev"_s;
80 return u"CumulativeCut"_s;
81 default:
82 break;
83 }
84 return u"None"_s;
85}
86
88{
89 if ( limits == "MinMax"_L1 )
90 {
92 }
93 else if ( limits == "StdDev"_L1 )
94 {
96 }
97 else if ( limits == "CumulativeCut"_L1 )
98 {
100 }
102}
103
105{
106 switch ( minMaxExtent )
107 {
109 return u"WholeRaster"_s;
111 return u"CurrentCanvas"_s;
113 return u"UpdatedCanvas"_s;
114 }
115 return u"WholeRaster"_s;
116}
117
119{
120 if ( extent == "WholeRaster"_L1 )
121 {
123 }
124 else if ( extent == "CurrentCanvas"_L1 )
125 {
127 }
128 else if ( extent == "UpdatedCanvas"_L1 )
129 {
131 }
132 else
133 {
135 }
136}
137
139{
140 switch ( accuracy )
141 {
143 return u"Exact"_s;
145 return u"Estimated"_s;
146 }
148}
149
151{
152 if ( accuracy == "Exact"_L1 )
155}
156
157void QgsRasterMinMaxOrigin::writeXml( QDomDocument &doc, QDomElement &parentElem ) const
158{
159 // limits
160 QDomElement limitsElem = doc.createElement( u"limits"_s );
161 const QDomText limitsText = doc.createTextNode( limitsString( mLimits ) );
162 limitsElem.appendChild( limitsText );
163 parentElem.appendChild( limitsElem );
164
165 // extent
166 QDomElement extentElem = doc.createElement( u"extent"_s );
167 const QDomText extentText = doc.createTextNode( extentString( mExtent ) );
168 extentElem.appendChild( extentText );
169 parentElem.appendChild( extentElem );
170
171 // statAccuracy
172 QDomElement statAccuracyElem = doc.createElement( u"statAccuracy"_s );
173 const QDomText statAccuracyText = doc.createTextNode( statAccuracyString( mAccuracy ) );
174 statAccuracyElem.appendChild( statAccuracyText );
175 parentElem.appendChild( statAccuracyElem );
176
177 // mCumulativeCutLower
178 QDomElement cumulativeCutLowerElem = doc.createElement( u"cumulativeCutLower"_s );
179 const QDomText cumulativeCutLowerText = doc.createTextNode( QString::number( mCumulativeCutLower ) );
180 cumulativeCutLowerElem.appendChild( cumulativeCutLowerText );
181 parentElem.appendChild( cumulativeCutLowerElem );
182
183 // mCumulativeCutUpper
184 QDomElement cumulativeCutUpperElem = doc.createElement( u"cumulativeCutUpper"_s );
185 const QDomText cumulativeCutUpperText = doc.createTextNode( QString::number( mCumulativeCutUpper ) );
186 cumulativeCutUpperElem.appendChild( cumulativeCutUpperText );
187 parentElem.appendChild( cumulativeCutUpperElem );
188
189 // mCumulativeCutUpper
190 QDomElement stdDevFactorElem = doc.createElement( u"stdDevFactor"_s );
191 const QDomText stdDevFactorText = doc.createTextNode( QString::number( mStdDevFactor ) );
192 stdDevFactorElem.appendChild( stdDevFactorText );
193 parentElem.appendChild( stdDevFactorElem );
194}
195
196void QgsRasterMinMaxOrigin::readXml( const QDomElement &elem )
197{
198 const QDomElement limitsElem = elem.firstChildElement( u"limits"_s );
199 if ( !limitsElem.isNull() )
200 {
201 mLimits = limitsFromString( limitsElem.text() );
202 }
203
204 const QDomElement extentElem = elem.firstChildElement( u"extent"_s );
205 if ( !extentElem.isNull() )
206 {
207 mExtent = extentFromString( extentElem.text() );
208 }
209
210 const QDomElement statAccuracyElem = elem.firstChildElement( u"statAccuracy"_s );
211 if ( !statAccuracyElem.isNull() )
212 {
213 mAccuracy = statAccuracyFromString( statAccuracyElem.text() );
214 }
215
216 const QDomElement cumulativeCutLowerElem = elem.firstChildElement( u"cumulativeCutLower"_s );
217 if ( !cumulativeCutLowerElem.isNull() )
218 {
219 mCumulativeCutLower = cumulativeCutLowerElem.text().toDouble();
220 }
221
222 const QDomElement cumulativeCutUpperElem = elem.firstChildElement( u"cumulativeCutUpper"_s );
223 if ( !cumulativeCutUpperElem.isNull() )
224 {
225 mCumulativeCutUpper = cumulativeCutUpperElem.text().toDouble();
226 }
227
228 const QDomElement stdDevFactorElem = elem.firstChildElement( u"stdDevFactor"_s );
229 if ( !stdDevFactorElem.isNull() )
230 {
231 mStdDevFactor = stdDevFactorElem.text().toDouble();
232 }
233}
RasterRangeLimit
Describes the limits used to compute raster ranges (min/max values).
Definition qgis.h:1664
@ CumulativeCut
Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ].
Definition qgis.h:1668
@ StdDev
Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ].
Definition qgis.h:1667
@ MinimumMaximum
Real min-max values.
Definition qgis.h:1666
@ NotSet
User defined.
Definition qgis.h:1665
RasterRangeAccuracy
Describes the accuracy used to compute raster ranges (min/max values).
Definition qgis.h:1695
@ Exact
Exact statistics.
Definition qgis.h:1696
@ Estimated
Approximated statistics.
Definition qgis.h:1697
QFlags< SettingsOption > SettingsOptions
Definition qgis.h:756
RasterRangeExtent
Describes the extent used to compute raster ranges (min/max values).
Definition qgis.h:1680
@ UpdatedCanvas
Constantly updated extent of the canvas is used to compute statistics.
Definition qgis.h:1683
@ WholeRaster
Whole raster is used to compute statistics.
Definition qgis.h:1681
@ FixedCanvas
Current extent of the canvas (at the time of computation) is used to compute statistics.
Definition qgis.h:1682
static QString limitsString(Qgis::RasterRangeLimit limits)
Returns a string to serialize Limits.
Qgis::RasterRangeExtent extent() const
Returns the raster extent.
static Qgis::RasterRangeAccuracy statAccuracyFromString(const QString &accuracy)
Deserialize StatAccuracy.
static constexpr double CUMULATIVE_CUT_UPPER
Default cumulative cut upper limit.
static QString statAccuracyString(Qgis::RasterRangeAccuracy accuracy)
Returns a string to serialize StatAccuracy.
static constexpr double DEFAULT_STDDEV_FACTOR
Default standard deviation factor.
static QString extentString(Qgis::RasterRangeExtent extent)
Returns a string to serialize Extent.
static const QgsSettingsEntryDouble * settingsCumulativeCutUpper
bool operator==(const QgsRasterMinMaxOrigin &other) const
static constexpr double CUMULATIVE_CUT_LOWER
Default cumulative cut lower limit.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Serialize object.
void readXml(const QDomElement &elem)
Deserialize object.
static Qgis::RasterRangeLimit limitsFromString(const QString &limits)
Deserialize Limits.
Qgis::RasterRangeLimit limits() const
Returns the raster limits.
static const QgsSettingsEntryDouble * settingsCumulativeCutLower
static Qgis::RasterRangeExtent extentFromString(const QString &extent)
Deserialize Extent.
static const QgsSettingsEntryDouble * settingsDefaultStandardDeviation
A double settings entry.
static QgsSettingsTreeNode * sTreeRaster
#define BUILTIN_UNREACHABLE
Definition qgis.h:7714