QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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
22#include "qgssettings.h"
23
24#include <QDomDocument>
25#include <QDomElement>
26#include <QString>
27
28using namespace Qt::StringLiterals;
29
31 : mCumulativeCutLower( CUMULATIVE_CUT_LOWER )
32 , mCumulativeCutUpper( CUMULATIVE_CUT_UPPER )
33 , mStdDevFactor( DEFAULT_STDDEV_FACTOR )
34{
35 const QgsSettings mySettings;
36 mCumulativeCutLower = mySettings.value( u"Raster/cumulativeCutLower"_s, CUMULATIVE_CUT_LOWER ).toDouble();
37 mCumulativeCutUpper = mySettings.value( u"Raster/cumulativeCutUpper"_s, CUMULATIVE_CUT_UPPER ).toDouble();
38 mStdDevFactor = mySettings.value( u"Raster/defaultStandardDeviation"_s, DEFAULT_STDDEV_FACTOR ).toDouble();
39}
40
42{
43 return mLimits == other.mLimits &&
44 mExtent == other.mExtent &&
45 mAccuracy == other.mAccuracy &&
46 std::fabs( mCumulativeCutLower - other.mCumulativeCutLower ) < 1e-5 &&
47 std::fabs( mCumulativeCutUpper - other.mCumulativeCutUpper ) < 1e-5 &&
48 std::fabs( mStdDevFactor - other.mStdDevFactor ) < 1e-5;
49}
50
52{
53 switch ( limits )
54 {
56 return u"MinMax"_s;
58 return u"StdDev"_s;
60 return u"CumulativeCut"_s;
61 default:
62 break;
63 }
64 return u"None"_s;
65}
66
68{
69 if ( limits == "MinMax"_L1 )
70 {
72 }
73 else if ( limits == "StdDev"_L1 )
74 {
76 }
77 else if ( limits == "CumulativeCut"_L1 )
78 {
80 }
82}
83
85{
86 switch ( minMaxExtent )
87 {
89 return u"WholeRaster"_s;
91 return u"CurrentCanvas"_s;
93 return u"UpdatedCanvas"_s;
94 }
95 return u"WholeRaster"_s;
96}
97
99{
100 if ( extent == "WholeRaster"_L1 )
101 {
103 }
104 else if ( extent == "CurrentCanvas"_L1 )
105 {
107 }
108 else if ( extent == "UpdatedCanvas"_L1 )
109 {
111 }
112 else
113 {
115 }
116}
117
119{
120 switch ( accuracy )
121 {
123 return u"Exact"_s;
125 return u"Estimated"_s;
126 }
128}
129
131{
132 if ( accuracy == "Exact"_L1 )
135}
136
137void QgsRasterMinMaxOrigin::writeXml( QDomDocument &doc, QDomElement &parentElem ) const
138{
139 // limits
140 QDomElement limitsElem = doc.createElement( u"limits"_s );
141 const QDomText limitsText = doc.createTextNode( limitsString( mLimits ) );
142 limitsElem.appendChild( limitsText );
143 parentElem.appendChild( limitsElem );
144
145 // extent
146 QDomElement extentElem = doc.createElement( u"extent"_s );
147 const QDomText extentText = doc.createTextNode( extentString( mExtent ) );
148 extentElem.appendChild( extentText );
149 parentElem.appendChild( extentElem );
150
151 // statAccuracy
152 QDomElement statAccuracyElem = doc.createElement( u"statAccuracy"_s );
153 const QDomText statAccuracyText = doc.createTextNode( statAccuracyString( mAccuracy ) );
154 statAccuracyElem.appendChild( statAccuracyText );
155 parentElem.appendChild( statAccuracyElem );
156
157 // mCumulativeCutLower
158 QDomElement cumulativeCutLowerElem = doc.createElement( u"cumulativeCutLower"_s );
159 const QDomText cumulativeCutLowerText = doc.createTextNode( QString::number( mCumulativeCutLower ) );
160 cumulativeCutLowerElem.appendChild( cumulativeCutLowerText );
161 parentElem.appendChild( cumulativeCutLowerElem );
162
163 // mCumulativeCutUpper
164 QDomElement cumulativeCutUpperElem = doc.createElement( u"cumulativeCutUpper"_s );
165 const QDomText cumulativeCutUpperText = doc.createTextNode( QString::number( mCumulativeCutUpper ) );
166 cumulativeCutUpperElem.appendChild( cumulativeCutUpperText );
167 parentElem.appendChild( cumulativeCutUpperElem );
168
169 // mCumulativeCutUpper
170 QDomElement stdDevFactorElem = doc.createElement( u"stdDevFactor"_s );
171 const QDomText stdDevFactorText = doc.createTextNode( QString::number( mStdDevFactor ) );
172 stdDevFactorElem.appendChild( stdDevFactorText );
173 parentElem.appendChild( stdDevFactorElem );
174}
175
176void QgsRasterMinMaxOrigin::readXml( const QDomElement &elem )
177{
178 const QDomElement limitsElem = elem.firstChildElement( u"limits"_s );
179 if ( !limitsElem.isNull() )
180 {
181 mLimits = limitsFromString( limitsElem.text() );
182 }
183
184 const QDomElement extentElem = elem.firstChildElement( u"extent"_s );
185 if ( !extentElem.isNull() )
186 {
187 mExtent = extentFromString( extentElem.text() );
188 }
189
190 const QDomElement statAccuracyElem = elem.firstChildElement( u"statAccuracy"_s );
191 if ( !statAccuracyElem.isNull() )
192 {
193 mAccuracy = statAccuracyFromString( statAccuracyElem.text() );
194 }
195
196 const QDomElement cumulativeCutLowerElem = elem.firstChildElement( u"cumulativeCutLower"_s );
197 if ( !cumulativeCutLowerElem.isNull() )
198 {
199 mCumulativeCutLower = cumulativeCutLowerElem.text().toDouble();
200 }
201
202 const QDomElement cumulativeCutUpperElem = elem.firstChildElement( u"cumulativeCutUpper"_s );
203 if ( !cumulativeCutUpperElem.isNull() )
204 {
205 mCumulativeCutUpper = cumulativeCutUpperElem.text().toDouble();
206 }
207
208 const QDomElement stdDevFactorElem = elem.firstChildElement( u"stdDevFactor"_s );
209 if ( !stdDevFactorElem.isNull() )
210 {
211 mStdDevFactor = stdDevFactorElem.text().toDouble();
212 }
213}
RasterRangeLimit
Describes the limits used to compute raster ranges (min/max values).
Definition qgis.h:1602
@ CumulativeCut
Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ].
Definition qgis.h:1606
@ StdDev
Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ].
Definition qgis.h:1605
@ MinimumMaximum
Real min-max values.
Definition qgis.h:1604
@ NotSet
User defined.
Definition qgis.h:1603
RasterRangeAccuracy
Describes the accuracy used to compute raster ranges (min/max values).
Definition qgis.h:1633
@ Exact
Exact statistics.
Definition qgis.h:1634
@ Estimated
Approximated statistics.
Definition qgis.h:1635
RasterRangeExtent
Describes the extent used to compute raster ranges (min/max values).
Definition qgis.h:1618
@ UpdatedCanvas
Constantly updated extent of the canvas is used to compute statistics.
Definition qgis.h:1621
@ WholeRaster
Whole raster is used to compute statistics.
Definition qgis.h:1619
@ FixedCanvas
Current extent of the canvas (at the time of computation) is used to compute statistics.
Definition qgis.h:1620
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.
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 Qgis::RasterRangeExtent extentFromString(const QString &extent)
Deserialize Extent.
Stores settings for use within QGIS.
Definition qgssettings.h:68
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
#define BUILTIN_UNREACHABLE
Definition qgis.h:7513