QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
28 : mCumulativeCutLower( CUMULATIVE_CUT_LOWER )
29 , mCumulativeCutUpper( CUMULATIVE_CUT_UPPER )
30 , mStdDevFactor( DEFAULT_STDDEV_FACTOR )
31{
32 const QgsSettings mySettings;
33 mCumulativeCutLower = mySettings.value( QStringLiteral( "Raster/cumulativeCutLower" ), CUMULATIVE_CUT_LOWER ).toDouble();
34 mCumulativeCutUpper = mySettings.value( QStringLiteral( "Raster/cumulativeCutUpper" ), CUMULATIVE_CUT_UPPER ).toDouble();
35 mStdDevFactor = mySettings.value( QStringLiteral( "Raster/defaultStandardDeviation" ), DEFAULT_STDDEV_FACTOR ).toDouble();
36}
37
39{
40 return mLimits == other.mLimits &&
41 mExtent == other.mExtent &&
42 mAccuracy == other.mAccuracy &&
43 std::fabs( mCumulativeCutLower - other.mCumulativeCutLower ) < 1e-5 &&
44 std::fabs( mCumulativeCutUpper - other.mCumulativeCutUpper ) < 1e-5 &&
45 std::fabs( mStdDevFactor - other.mStdDevFactor ) < 1e-5;
46}
47
49{
50 switch ( limits )
51 {
53 return QStringLiteral( "MinMax" );
55 return QStringLiteral( "StdDev" );
57 return QStringLiteral( "CumulativeCut" );
58 default:
59 break;
60 }
61 return QStringLiteral( "None" );
62}
63
65{
66 if ( limits == QLatin1String( "MinMax" ) )
67 {
69 }
70 else if ( limits == QLatin1String( "StdDev" ) )
71 {
73 }
74 else if ( limits == QLatin1String( "CumulativeCut" ) )
75 {
77 }
79}
80
82{
83 switch ( minMaxExtent )
84 {
86 return QStringLiteral( "WholeRaster" );
88 return QStringLiteral( "CurrentCanvas" );
90 return QStringLiteral( "UpdatedCanvas" );
91 }
92 return QStringLiteral( "WholeRaster" );
93}
94
96{
97 if ( extent == QLatin1String( "WholeRaster" ) )
98 {
100 }
101 else if ( extent == QLatin1String( "CurrentCanvas" ) )
102 {
104 }
105 else if ( extent == QLatin1String( "UpdatedCanvas" ) )
106 {
108 }
109 else
110 {
112 }
113}
114
116{
117 switch ( accuracy )
118 {
120 return QStringLiteral( "Exact" );
122 return QStringLiteral( "Estimated" );
123 }
125}
126
128{
129 if ( accuracy == QLatin1String( "Exact" ) )
132}
133
134void QgsRasterMinMaxOrigin::writeXml( QDomDocument &doc, QDomElement &parentElem ) const
135{
136 // limits
137 QDomElement limitsElem = doc.createElement( QStringLiteral( "limits" ) );
138 const QDomText limitsText = doc.createTextNode( limitsString( mLimits ) );
139 limitsElem.appendChild( limitsText );
140 parentElem.appendChild( limitsElem );
141
142 // extent
143 QDomElement extentElem = doc.createElement( QStringLiteral( "extent" ) );
144 const QDomText extentText = doc.createTextNode( extentString( mExtent ) );
145 extentElem.appendChild( extentText );
146 parentElem.appendChild( extentElem );
147
148 // statAccuracy
149 QDomElement statAccuracyElem = doc.createElement( QStringLiteral( "statAccuracy" ) );
150 const QDomText statAccuracyText = doc.createTextNode( statAccuracyString( mAccuracy ) );
151 statAccuracyElem.appendChild( statAccuracyText );
152 parentElem.appendChild( statAccuracyElem );
153
154 // mCumulativeCutLower
155 QDomElement cumulativeCutLowerElem = doc.createElement( QStringLiteral( "cumulativeCutLower" ) );
156 const QDomText cumulativeCutLowerText = doc.createTextNode( QString::number( mCumulativeCutLower ) );
157 cumulativeCutLowerElem.appendChild( cumulativeCutLowerText );
158 parentElem.appendChild( cumulativeCutLowerElem );
159
160 // mCumulativeCutUpper
161 QDomElement cumulativeCutUpperElem = doc.createElement( QStringLiteral( "cumulativeCutUpper" ) );
162 const QDomText cumulativeCutUpperText = doc.createTextNode( QString::number( mCumulativeCutUpper ) );
163 cumulativeCutUpperElem.appendChild( cumulativeCutUpperText );
164 parentElem.appendChild( cumulativeCutUpperElem );
165
166 // mCumulativeCutUpper
167 QDomElement stdDevFactorElem = doc.createElement( QStringLiteral( "stdDevFactor" ) );
168 const QDomText stdDevFactorText = doc.createTextNode( QString::number( mStdDevFactor ) );
169 stdDevFactorElem.appendChild( stdDevFactorText );
170 parentElem.appendChild( stdDevFactorElem );
171}
172
173void QgsRasterMinMaxOrigin::readXml( const QDomElement &elem )
174{
175 const QDomElement limitsElem = elem.firstChildElement( QStringLiteral( "limits" ) );
176 if ( !limitsElem.isNull() )
177 {
178 mLimits = limitsFromString( limitsElem.text() );
179 }
180
181 const QDomElement extentElem = elem.firstChildElement( QStringLiteral( "extent" ) );
182 if ( !extentElem.isNull() )
183 {
184 mExtent = extentFromString( extentElem.text() );
185 }
186
187 const QDomElement statAccuracyElem = elem.firstChildElement( QStringLiteral( "statAccuracy" ) );
188 if ( !statAccuracyElem.isNull() )
189 {
190 mAccuracy = statAccuracyFromString( statAccuracyElem.text() );
191 }
192
193 const QDomElement cumulativeCutLowerElem = elem.firstChildElement( QStringLiteral( "cumulativeCutLower" ) );
194 if ( !cumulativeCutLowerElem.isNull() )
195 {
196 mCumulativeCutLower = cumulativeCutLowerElem.text().toDouble();
197 }
198
199 const QDomElement cumulativeCutUpperElem = elem.firstChildElement( QStringLiteral( "cumulativeCutUpper" ) );
200 if ( !cumulativeCutUpperElem.isNull() )
201 {
202 mCumulativeCutUpper = cumulativeCutUpperElem.text().toDouble();
203 }
204
205 const QDomElement stdDevFactorElem = elem.firstChildElement( QStringLiteral( "stdDevFactor" ) );
206 if ( !stdDevFactorElem.isNull() )
207 {
208 mStdDevFactor = stdDevFactorElem.text().toDouble();
209 }
210}
RasterRangeLimit
Describes the limits used to compute raster ranges (min/max values).
Definition qgis.h:1544
@ CumulativeCut
Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ].
Definition qgis.h:1548
@ StdDev
Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ].
Definition qgis.h:1547
@ MinimumMaximum
Real min-max values.
Definition qgis.h:1546
@ NotSet
User defined.
Definition qgis.h:1545
RasterRangeAccuracy
Describes the accuracy used to compute raster ranges (min/max values).
Definition qgis.h:1575
@ Exact
Exact statistics.
Definition qgis.h:1576
@ Estimated
Approximated statistics.
Definition qgis.h:1577
RasterRangeExtent
Describes the extent used to compute raster ranges (min/max values).
Definition qgis.h:1560
@ UpdatedCanvas
Constantly updated extent of the canvas is used to compute statistics.
Definition qgis.h:1563
@ WholeRaster
Whole raster is used to compute statistics.
Definition qgis.h:1561
@ FixedCanvas
Current extent of the canvas (at the time of computation) is used to compute statistics.
Definition qgis.h:1562
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:65
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:7208