Skip to content

Commit 792873a

Browse files
authored
Merge pull request #3871 from rouault/auto_stretch
[FEATURE] Implement raster auto-stretching when updating canvas
2 parents 5dc39e0 + 532eb58 commit 792873a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1926
-889
lines changed

doc/api_break.dox

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,14 @@ QgsProject {#qgis_api_break_3_0_QgsProject}
13131313
- clearProperties() was removed. Use clear() instead.
13141314

13151315

1316+
QgsRaster {#qgis_api_break_3_0_QgsRaster}
1317+
---------
1318+
1319+
- QgsRaster::ContrastEnhancementLimits has been removed, use QgsRasterMinMaxOrigin::Limits
1320+
- QgsRaster::contrastEnhancementLimitsAsString() has been removed, use QgsRasterMinMaxOrigin::limitsString()
1321+
- QgsRaster::contrastEnhancementLimitsFromString() has been removed, use QgsRasterMinMaxOrigin::limitsFromString()
1322+
1323+
13161324
QgsRasterCalcNode {#qgis_api_break_3_0_QgsRasterCalcNode}
13171325
-----------------
13181326

@@ -1343,13 +1351,18 @@ QgsRasterLayer {#qgis_api_break_3_0_QgsRasterLayer}
13431351
- setDrawingStyle() was removed. Use setRendererForDrawingStyle() or setRenderer() instead.
13441352
- previewAsPixmap() was removed. Use previewAsImage() instead.
13451353
- updateProgress() had no effect and was removed.
1346-
1354+
- CUMULATIVE_CUT_LOWER and CUMULATIVE_CUT_UPPER have been moved to QgsRasterMinMaxOrigin
1355+
- the second parameter of setContrastEnhancement() has changed type. It is now QgsRasterMinMaxOrigin::Limits
13471356

13481357
QgsRasterProjector {#qgis_api_break_3_0_QgsRasterProjector}
13491358
------------------
13501359

13511360
- extentSize() now takes a QgsCoordinateTransform reference, not a pointer. An invalid QgsCoordinateTransform should be used instead of a null pointer if no transformation is required.
13521361

1362+
QgsRasterRenderer
1363+
-----------------
1364+
1365+
- MinMaxOrigin enum, minMaxOriginName(), minMaxOriginLabel(), minMaxOriginFromName() removed. Use minMaxOrigin() instead
13531366

13541367
QgsRelation {#qgis_api_break_3_0_QgsRelation}
13551368
-----------
@@ -1430,6 +1443,12 @@ QgsSimpleMarkerSymbolLayerWidget {#qgis_api_break_3_0_QgsSimpleMarkerSymb
14301443
- setName() was removed.
14311444

14321445

1446+
QgsSingleBandPseudoColorRenderer {#qgis_api_break_3_0_QgsSingleBandPseudoColorRenderer}
1447+
--------------------------------
1448+
1449+
- classificationMinMaxOrigin() and setClassificationMinMaxOrigin() removed. Use minMaxOrigin() and setMinMaxOrigin()
1450+
1451+
14331452
QgsSingleSymbolRendererWidget {#qgis_api_break_3_0_QgsSingleSymbolRendererWidget}
14341453
-----------------------------
14351454

python/core/core.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
%Include raster/qgsrasterinterface.sip
275275
%Include raster/qgsrasteriterator.sip
276276
%Include raster/qgsrasterlayer.sip
277+
%Include raster/qgsrasterminmaxorigin.sip
277278
%Include raster/qgsrasternuller.sip
278279
%Include raster/qgsrasterpipe.sip
279280
%Include raster/qgsrasterprojector.sip

python/core/raster/qgsraster.sip

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ class QgsRaster
6262
PyramidsErdas,
6363
};
6464

65-
/** \brief Contrast enhancement limits */
66-
enum ContrastEnhancementLimits
67-
{
68-
ContrastEnhancementNone,
69-
ContrastEnhancementMinMax,
70-
ContrastEnhancementStdDev,
71-
ContrastEnhancementCumulativeCut
72-
};
7365

7466
/** \brief This enumerator describes the different kinds of drawing we can do */
7567
enum DrawingStyle
@@ -87,9 +79,6 @@ class QgsRaster
8779
SingleBandColorDataStyle // ARGB values rendered directly
8880
};
8981

90-
static QString contrastEnhancementLimitsAsString( QgsRaster::ContrastEnhancementLimits theLimits );
91-
static ContrastEnhancementLimits contrastEnhancementLimitsFromString( const QString& theLimits );
92-
9382
/** Get value representable by given data type.
9483
* Supported are numerical types Byte, UInt16, Int16, UInt32, Int32, Float32, Float64.
9584
* @param value

python/core/raster/qgsrasterlayer.sip

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ class QgsRasterLayer : QgsMapLayer
1010
%End
1111

1212
public:
13-
/** \brief Default cumulative cut lower limit */
14-
static const double CUMULATIVE_CUT_LOWER;
15-
16-
/** \brief Default cumulative cut upper limit */
17-
static const double CUMULATIVE_CUT_UPPER;
1813

1914
/** \brief Default sample size (number of pixels) for estimated statistics/histogram calculation */
2015
static const double SAMPLE_SIZE;
@@ -165,7 +160,7 @@ class QgsRasterLayer : QgsMapLayer
165160

166161

167162
void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
168-
QgsRaster::ContrastEnhancementLimits theLimits = QgsRaster::ContrastEnhancementMinMax,
163+
QgsRasterMinMaxOrigin::Limits theLimits = QgsRasterMinMaxOrigin::MinMax,
169164
const QgsRectangle& theExtent = QgsRectangle(),
170165
int theSampleSize = QgsRasterLayer::SAMPLE_SIZE,
171166
bool theGenerateLookupTableFlag = true );
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/** \class QgsRasterMinMaxOrigin
2+
* This class describes the origin of min/max values. It does not store by
3+
* itself the min/max values.
4+
*/
5+
6+
class QgsRasterMinMaxOrigin
7+
{
8+
%TypeHeaderCode
9+
#include <qgsrasterminmaxorigin.h>
10+
%End
11+
public:
12+
//! \brief Default cumulative cut lower limit
13+
static const double CUMULATIVE_CUT_LOWER;
14+
15+
//! \brief Default cumulative cut upper limit
16+
static const double CUMULATIVE_CUT_UPPER;
17+
18+
//! \brief Default standard deviation factor
19+
static const double DEFAULT_STDDEV_FACTOR;
20+
21+
//! \brief This enumerator describes the limits used to compute min/max values
22+
enum Limits
23+
{
24+
//! User defined.
25+
None /PyName=None_/,
26+
//! Real min-max values
27+
MinMax,
28+
//! Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ]
29+
StdDev,
30+
//! Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]
31+
CumulativeCut
32+
};
33+
34+
//! \brief This enumerator describes the extent used to compute min/max values
35+
enum Extent
36+
{
37+
//! Whole raster is used to compute statistics.
38+
WholeRaster,
39+
//! Current extent of the canvas (at the time of computation) is used to compute statistics.
40+
CurrentCanvas,
41+
//! Constantly updated extent of the canvas is used to compute statistics.
42+
UpdatedCanvas
43+
};
44+
45+
//! \brief This enumerator describes the accuracy used to compute statistics.
46+
enum StatAccuracy
47+
{
48+
//! Exact statistics.
49+
Exact,
50+
//! Approximated statistics.
51+
Estimated
52+
};
53+
54+
//! \brief Default constructor.
55+
QgsRasterMinMaxOrigin();
56+
57+
//! \brief Equality operator.
58+
bool operator ==( const QgsRasterMinMaxOrigin& other ) const;
59+
60+
//////// Getter methods /////////////////////
61+
62+
//! \brief Return limits.
63+
QgsRasterMinMaxOrigin::Limits limits() const;
64+
65+
//! \brief Return extent.
66+
QgsRasterMinMaxOrigin::Extent extent() const;
67+
68+
//! \brief Return statistic accuracy.
69+
QgsRasterMinMaxOrigin::StatAccuracy statAccuracy() const;
70+
71+
//! \brief Return lower bound of cumulative cut method (between 0 and 1).
72+
double cumulativeCutLower() const;
73+
74+
//! \brief Return upper bound of cumulative cut method (between 0 and 1).
75+
double cumulativeCutUpper() const;
76+
77+
//! \brief Return factor f so that the min/max range is [ mean - f * stddev , mean + f * stddev ]
78+
double stdDevFactor() const;
79+
80+
//////// Setter methods /////////////////////
81+
82+
//! \brief Set limits.
83+
void setLimits(QgsRasterMinMaxOrigin::Limits theLimits);
84+
85+
//! \brief Set extent.
86+
void setExtent(QgsRasterMinMaxOrigin::Extent theExtent);
87+
88+
//! \brief Set statistics accuracy.
89+
void setStatAccuracy(QgsRasterMinMaxOrigin::StatAccuracy theAccuracy);
90+
91+
//! \brief Set lower bound of cumulative cut method (between 0 and 1).
92+
void setCumulativeCutLower(double val);
93+
94+
//! \brief Set upper bound of cumulative cut method (between 0 and 1).
95+
void setCumulativeCutUpper(double val);
96+
97+
//! \brief Set factor f so that the min/max range is [ mean - f * stddev , mean + f * stddev ]
98+
void setStdDevFactor(double val);
99+
100+
//////// XML serialization /////////////////////
101+
102+
//! \brief Serialize object.
103+
void writeXml( QDomDocument& doc, QDomElement& parentElem ) const;
104+
105+
//! \brief Deserialize object.
106+
void readXml( const QDomElement& elem );
107+
108+
//////// Static methods /////////////////////
109+
110+
//! \brief Return a string to serialize Limits
111+
static QString limitsString( QgsRasterMinMaxOrigin::Limits theLimits );
112+
113+
//! \brief Deserialize Limits
114+
static QgsRasterMinMaxOrigin::Limits limitsFromString( const QString& theLimits );
115+
116+
//! \brief Return a string to serialize Extent
117+
static QString extentString( QgsRasterMinMaxOrigin::Extent theExtent );
118+
119+
//! \brief Deserialize Extent
120+
static QgsRasterMinMaxOrigin::Extent extentFromString( const QString& theExtent );
121+
122+
//! \brief Return a string to serialize StatAccuracy
123+
static QString statAccuracyString( QgsRasterMinMaxOrigin::StatAccuracy theAccuracy );
124+
125+
//! \brief Deserialize StatAccuracy
126+
static QgsRasterMinMaxOrigin::StatAccuracy statAccuracyFromString( const QString& theAccuracy );
127+
};

python/core/raster/qgsrasterrenderer.sip

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,6 @@ class QgsRasterRenderer : QgsRasterInterface
66
%End
77

88
public:
9-
// Origin of min / max values
10-
enum MinMaxOrigin
11-
{
12-
MinMaxUnknown,
13-
MinMaxUser, // entered by user
14-
// method
15-
MinMaxMinMax,
16-
MinMaxCumulativeCut,
17-
MinMaxStdDev,
18-
// Extent
19-
MinMaxFullExtent,
20-
MinMaxSubExtent,
21-
// Precision
22-
MinMaxEstimated,
23-
MinMaxExact
24-
};
259

2610
static const QRgb NODATA_COLOR;
2711

@@ -60,14 +44,16 @@ class QgsRasterRenderer : QgsRasterInterface
6044
/** Copies common properties like opacity / transparency data from other renderer.
6145
* Useful when cloning renderers.
6246
* @note added in 2.16 */
63-
void copyCommonProperties( const QgsRasterRenderer* other );
47+
void copyCommonProperties( const QgsRasterRenderer* other, bool copyMinMaxOrigin = true );
6448

6549
/** Returns a list of band numbers used by the renderer*/
6650
virtual QList<int> usesBands() const;
6751

68-
static QString minMaxOriginName( int theOrigin );
69-
static QString minMaxOriginLabel( int theOrigin );
70-
static int minMaxOriginFromName( const QString& theName );
52+
//! Returns const reference to origin of min/max values
53+
const QgsRasterMinMaxOrigin& minMaxOrigin() const;
54+
55+
//! Sets origin of min/max values
56+
void setMinMaxOrigin( const QgsRasterMinMaxOrigin& theOrigin );
7157

7258
protected:
7359

python/core/raster/qgssinglebandpseudocolorrenderer.sip

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class QgsSingleBandPseudoColorRenderer: QgsRasterRenderer
4040
double classificationMax() const;
4141
void setClassificationMin( double min );
4242
void setClassificationMax( double max );
43-
int classificationMinMaxOrigin() const;
44-
void setClassificationMinMaxOrigin( int origin );
4543

4644
private:
4745

python/gui/raster/qgsmultibandcolorrendererwidget.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class QgsMultiBandColorRendererWidget: QgsRasterRendererWidget
1919
void setMin( const QString& value, int index = 0 );
2020
void setMax( const QString& value, int index = 0 );
2121
int selectedBand( int index = 0 );
22+
void doComputations();
2223

2324
public slots:
24-
void loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin );
25+
void loadMinMax( int theBandNo, double theMin, double theMax );
2526
};

python/gui/raster/qgsrasterminmaxwidget.sip

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,34 @@ class QgsRasterMinMaxWidget: QWidget
3737
/** Return the selected sample size. */
3838
int sampleSize();
3939

40-
// Load programmaticaly with current values
41-
void load();
40+
//! \brief Set the "source" of min/max values.
41+
void setFromMinMaxOrigin( const QgsRasterMinMaxOrigin& );
42+
43+
//! \brief Return a QgsRasterMinMaxOrigin object with the widget values.
44+
QgsRasterMinMaxOrigin minMaxOrigin();
45+
46+
//! Hide updated extent radio button
47+
void hideUpdatedExtent();
48+
49+
//! Load programmaticaly with current values
50+
void doComputations();
51+
52+
//! Uncheck cumulative cut, min/max, std-dev radio buttons
53+
void userHasSetManualMinMaxValues();
54+
55+
//! Return if the widget is collaped.
56+
bool isCollapsed() const;
57+
58+
//! Set collapsed state of widget
59+
void setCollapsed(bool b);
4260

4361
signals:
44-
void load( int theBandNo, double theMin, double theMax, int origin );
62+
/**
63+
* Emitted when something on the widget has changed.
64+
* All widgets will fire this event to notify of an internal change.
65+
*/
66+
void widgetChanged();
67+
68+
//! signal emitted when new min/max values are computed from statistics.
69+
void load( int theBandNo, double theMin, double theMax );
4570
};

python/gui/raster/qgsrasterrendererwidget.sip

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ class QgsRasterRendererWidget: QWidget
77
QgsRasterRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent );
88
virtual ~QgsRasterRendererWidget();
99

10-
enum LoadMinMaxAlgo
11-
{
12-
Estimate,
13-
Actual,
14-
CurrentExtent,
15-
CumulativeCut // 2 - 98% cumulative cut
16-
};
17-
1810
virtual QgsRasterRenderer* renderer() = 0 /Factory/;
1911

2012
void setRasterLayer( QgsRasterLayer* layer );
@@ -42,6 +34,8 @@ class QgsRasterRendererWidget: QWidget
4234
virtual QString stdDev();
4335
virtual void setStdDev( const QString& value );
4436
virtual int selectedBand( int index = 0 );
37+
virtual void doComputations();
38+
virtual QgsRasterMinMaxWidget* minMaxWidget();
4539

4640
signals:
4741
/**

0 commit comments

Comments
 (0)