QGIS API Documentation 3.41.0-Master (cea29feecf2)
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#include "qgssettings.h"
20
21#include <QDomDocument>
22#include <QDomElement>
23#include <cmath>
24
26 : mCumulativeCutLower( CUMULATIVE_CUT_LOWER )
27 , mCumulativeCutUpper( CUMULATIVE_CUT_UPPER )
28 , mStdDevFactor( DEFAULT_STDDEV_FACTOR )
29{
30 const QgsSettings mySettings;
31 mCumulativeCutLower = mySettings.value( QStringLiteral( "Raster/cumulativeCutLower" ), CUMULATIVE_CUT_LOWER ).toDouble();
32 mCumulativeCutUpper = mySettings.value( QStringLiteral( "Raster/cumulativeCutUpper" ), CUMULATIVE_CUT_UPPER ).toDouble();
33 mStdDevFactor = mySettings.value( QStringLiteral( "Raster/defaultStandardDeviation" ), DEFAULT_STDDEV_FACTOR ).toDouble();
34}
35
37{
38 return mLimits == other.mLimits &&
39 mExtent == other.mExtent &&
40 mAccuracy == other.mAccuracy &&
41 std::fabs( mCumulativeCutLower - other.mCumulativeCutLower ) < 1e-5 &&
42 std::fabs( mCumulativeCutUpper - other.mCumulativeCutUpper ) < 1e-5 &&
43 std::fabs( mStdDevFactor - other.mStdDevFactor ) < 1e-5;
44}
45
47{
48 switch ( limits )
49 {
51 return QStringLiteral( "MinMax" );
53 return QStringLiteral( "StdDev" );
55 return QStringLiteral( "CumulativeCut" );
56 default:
57 break;
58 }
59 return QStringLiteral( "None" );
60}
61
63{
64 if ( limits == QLatin1String( "MinMax" ) )
65 {
67 }
68 else if ( limits == QLatin1String( "StdDev" ) )
69 {
71 }
72 else if ( limits == QLatin1String( "CumulativeCut" ) )
73 {
75 }
77}
78
80{
81 switch ( minMaxExtent )
82 {
84 return QStringLiteral( "WholeRaster" );
86 return QStringLiteral( "CurrentCanvas" );
88 return QStringLiteral( "UpdatedCanvas" );
89 }
90 return QStringLiteral( "WholeRaster" );
91}
92
94{
95 if ( extent == QLatin1String( "WholeRaster" ) )
96 {
98 }
99 else if ( extent == QLatin1String( "CurrentCanvas" ) )
100 {
102 }
103 else if ( extent == QLatin1String( "UpdatedCanvas" ) )
104 {
106 }
107 else
108 {
110 }
111}
112
114{
115 switch ( accuracy )
116 {
118 return QStringLiteral( "Exact" );
120 return QStringLiteral( "Estimated" );
121 }
123}
124
126{
127 if ( accuracy == QLatin1String( "Exact" ) )
130}
131
132void QgsRasterMinMaxOrigin::writeXml( QDomDocument &doc, QDomElement &parentElem ) const
133{
134 // limits
135 QDomElement limitsElem = doc.createElement( QStringLiteral( "limits" ) );
136 const QDomText limitsText = doc.createTextNode( limitsString( mLimits ) );
137 limitsElem.appendChild( limitsText );
138 parentElem.appendChild( limitsElem );
139
140 // extent
141 QDomElement extentElem = doc.createElement( QStringLiteral( "extent" ) );
142 const QDomText extentText = doc.createTextNode( extentString( mExtent ) );
143 extentElem.appendChild( extentText );
144 parentElem.appendChild( extentElem );
145
146 // statAccuracy
147 QDomElement statAccuracyElem = doc.createElement( QStringLiteral( "statAccuracy" ) );
148 const QDomText statAccuracyText = doc.createTextNode( statAccuracyString( mAccuracy ) );
149 statAccuracyElem.appendChild( statAccuracyText );
150 parentElem.appendChild( statAccuracyElem );
151
152 // mCumulativeCutLower
153 QDomElement cumulativeCutLowerElem = doc.createElement( QStringLiteral( "cumulativeCutLower" ) );
154 const QDomText cumulativeCutLowerText = doc.createTextNode( QString::number( mCumulativeCutLower ) );
155 cumulativeCutLowerElem.appendChild( cumulativeCutLowerText );
156 parentElem.appendChild( cumulativeCutLowerElem );
157
158 // mCumulativeCutUpper
159 QDomElement cumulativeCutUpperElem = doc.createElement( QStringLiteral( "cumulativeCutUpper" ) );
160 const QDomText cumulativeCutUpperText = doc.createTextNode( QString::number( mCumulativeCutUpper ) );
161 cumulativeCutUpperElem.appendChild( cumulativeCutUpperText );
162 parentElem.appendChild( cumulativeCutUpperElem );
163
164 // mCumulativeCutUpper
165 QDomElement stdDevFactorElem = doc.createElement( QStringLiteral( "stdDevFactor" ) );
166 const QDomText stdDevFactorText = doc.createTextNode( QString::number( mStdDevFactor ) );
167 stdDevFactorElem.appendChild( stdDevFactorText );
168 parentElem.appendChild( stdDevFactorElem );
169}
170
171void QgsRasterMinMaxOrigin::readXml( const QDomElement &elem )
172{
173 const QDomElement limitsElem = elem.firstChildElement( QStringLiteral( "limits" ) );
174 if ( !limitsElem.isNull() )
175 {
176 mLimits = limitsFromString( limitsElem.text() );
177 }
178
179 const QDomElement extentElem = elem.firstChildElement( QStringLiteral( "extent" ) );
180 if ( !extentElem.isNull() )
181 {
182 mExtent = extentFromString( extentElem.text() );
183 }
184
185 const QDomElement statAccuracyElem = elem.firstChildElement( QStringLiteral( "statAccuracy" ) );
186 if ( !statAccuracyElem.isNull() )
187 {
188 mAccuracy = statAccuracyFromString( statAccuracyElem.text() );
189 }
190
191 const QDomElement cumulativeCutLowerElem = elem.firstChildElement( QStringLiteral( "cumulativeCutLower" ) );
192 if ( !cumulativeCutLowerElem.isNull() )
193 {
194 mCumulativeCutLower = cumulativeCutLowerElem.text().toDouble();
195 }
196
197 const QDomElement cumulativeCutUpperElem = elem.firstChildElement( QStringLiteral( "cumulativeCutUpper" ) );
198 if ( !cumulativeCutUpperElem.isNull() )
199 {
200 mCumulativeCutUpper = cumulativeCutUpperElem.text().toDouble();
201 }
202
203 const QDomElement stdDevFactorElem = elem.firstChildElement( QStringLiteral( "stdDevFactor" ) );
204 if ( !stdDevFactorElem.isNull() )
205 {
206 mStdDevFactor = stdDevFactorElem.text().toDouble();
207 }
208}
RasterRangeLimit
Describes the limits used to compute raster ranges (min/max values).
Definition qgis.h:1436
@ CumulativeCut
Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ].
@ StdDev
Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ].
@ MinimumMaximum
Real min-max values.
@ NotSet
User defined.
RasterRangeAccuracy
Describes the accuracy used to compute raster ranges (min/max values).
Definition qgis.h:1467
@ Exact
Exact statistics.
@ Estimated
Approximated statistics.
RasterRangeExtent
Describes the extent used to compute raster ranges (min/max values).
Definition qgis.h:1452
@ UpdatedCanvas
Constantly updated extent of the canvas is used to compute statistics.
@ WholeRaster
Whole raster is used to compute statistics.
@ FixedCanvas
Current extent of the canvas (at the time of computation) is used to compute statistics.
This class describes the origin of min/max values.
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.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
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:6678