Skip to content

Commit 181f84b

Browse files
committed
[raster] move pseudocolor renderer classification out of gui into core
1 parent 792fcb5 commit 181f84b

15 files changed

+460
-274
lines changed

doc/api_break.dox

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ QgsColorRampShader {#qgis_api_break_3_0_QgsColorRampShader}
475475
------------------
476476

477477
- maximumColorCacheSize() and setMaximumColorCacheSize() were no longer used and are removed.
478+
- ColorRamp_TYPE enum was renamed to Type, and its value names decapitalized
478479

479480

480481
QgsComposerArrow {#qgis_api_break_3_0_QgsComposerArrow}
@@ -1465,6 +1466,7 @@ QgsSingleSymbolRendererWidget {#qgis_api_break_3_0_QgsSingleSymbolRendere
14651466
-----------------------------
14661467

14671468
- sizeScaleFieldChanged() and scaleMethodChanged() were removed. These settings are no longer exposed in the widget's GUI.
1469+
- The Mode enum was removed.
14681470

14691471

14701472
QgsSnapper {#qgis_api_break_3_0_QgsSnapper}

python/core/raster/qgscolorrampshader.sip

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,31 @@ class QgsColorRampShader : QgsRasterShaderFunction
55
%End
66

77
public:
8-
QgsColorRampShader( double theMinimumValue = 0.0, double theMaximumValue = 255.0 );
8+
//! Supported methods for color interpolation.
9+
enum Type
10+
{
11+
Interpolated, //!< Interpolates the color between two class breaks linearly.
12+
Discrete, //!< Assigns the color of the higher class for every pixel between two class breaks.
13+
Exact //!< Assigns the color of the exact matching value in the color ramp item list
14+
};
15+
16+
//! Classification modes used to create the color ramp shader
17+
enum ClassificationMode
18+
{
19+
Continuous = 1, //!< Uses breaks from color palette
20+
EqualInterval = 2, //!< Uses equal interval
21+
Quantile = 3 //!< Uses quantile (i.e. equal pixel) count
22+
};
23+
24+
/** Creates a new color ramp shader.
25+
* @param theMinimumValue minimum value for the raster shader
26+
* @param theMaximumValue maximum value for the raster shader
27+
* @param theType interpolation type used
28+
* @param theClassificationMode method used to classify the color ramp shader
29+
* @param theColorRamp vector color ramp used to classify the color ramp shader
30+
* @returns new QgsColorRampShader
31+
*/
32+
QgsColorRampShader( double theMinimumValue = 0.0, double theMaximumValue = 255.0, QgsColorRamp* theColorRamp = nullptr, Type theType = Interpolated, ClassificationMode theClassificationMode = Continuous );
933

1034
~QgsColorRampShader();
1135

@@ -28,19 +52,11 @@ class QgsColorRampShader : QgsRasterShaderFunction
2852
bool operator<( const QgsColorRampShader::ColorRampItem& other ) const;
2953
};
3054

31-
/** Supported methods for color interpolation. */
32-
enum ColorRamp_TYPE
33-
{
34-
INTERPOLATED, //!< Interpolates the color between two class breaks linearly.
35-
DISCRETE, //!< Assigns the color of the higher class for every pixel between two class breaks.
36-
EXACT //!< Assigns the color of the exact matching value in the color ramp item list
37-
};
38-
3955
/** \brief Get the custom colormap*/
4056
QList<QgsColorRampShader::ColorRampItem> colorRampItemList() const;
4157

4258
/** \brief Get the color ramp type */
43-
QgsColorRampShader::ColorRamp_TYPE colorRampType() const;
59+
Type colorRampType() const;
4460

4561
/** Get the source color ramp
4662
* @note added in QGIS 3.0
@@ -61,11 +77,27 @@ class QgsColorRampShader : QgsRasterShaderFunction
6177
void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList ); //TODO: sort on set
6278

6379
/** \brief Set the color ramp type*/
64-
void setColorRampType( QgsColorRampShader::ColorRamp_TYPE theColorRampType );
80+
void setColorRampType( QgsColorRampShader::Type theColorRampType );
6581

6682
/** \brief Set the color ramp type*/
6783
void setColorRampType( const QString& theType );
6884

85+
/** Classify color ramp shader
86+
* @param classes number of classes
87+
* @param band raster band used in classification (only used in quantile mode)
88+
* @param extent extent used in classification (only used in quantile mode)
89+
* @param input raster input used in classification (only used in quantile mode)
90+
*/
91+
void classifyColorRamp( const int classes = 0, const int band = -1, const QgsRectangle& extent = QgsRectangle(), QgsRasterInterface* input = nullptr );
92+
93+
/** Classify color ramp shader
94+
* @param band raster band used in classification (only used in quantile mode)
95+
* @param extent extent used in classification (only used in quantile mode)
96+
* @param input raster input used in classification (only used in quantile mode)
97+
*/
98+
void classifyColorRamp( const int band = -1, const QgsRectangle& extent = QgsRectangle(), QgsRasterInterface* input = nullptr ) /PyName=classifyColorRampV2/;
99+
100+
69101
/** \brief Generates and new RGB value based on one input value */
70102
bool shade( double, int* /Out/, int* /Out/, int* /Out/, int* /Out/ );
71103

@@ -74,6 +106,12 @@ class QgsColorRampShader : QgsRasterShaderFunction
74106

75107
void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;
76108

109+
//! Sets classification mode
110+
void setClassificationMode( ClassificationMode classificationMode );
111+
112+
//! Returns the classification mode
113+
ClassificationMode classificationMode() const;
114+
77115
/** Sets whether the shader should not render values out of range.
78116
* @param clip set to true to clip values which are out of range.
79117
* @see clip()

python/core/raster/qgssinglebandpseudocolorrenderer.sip

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class QgsSingleBandPseudoColorRenderer: QgsRasterRenderer
44
#include "qgssinglebandpseudocolorrenderer.h"
55
%End
66
public:
7+
78
/** Note: takes ownership of QgsRasterShader*/
89
QgsSingleBandPseudoColorRenderer( QgsRasterDataProvider* provider, int band, QgsRasterShader* shader /Transfer/ );
910
~QgsSingleBandPseudoColorRenderer();
@@ -15,10 +16,22 @@ class QgsSingleBandPseudoColorRenderer: QgsRasterRenderer
1516

1617
/** Takes ownership of the shader*/
1718
void setShader( QgsRasterShader* shader /Transfer/ );
19+
1820
QgsRasterShader* shader();
21+
1922
//! @note available in python as constShader
2023
const QgsRasterShader* shader() const /PyName=constShader/;
2124

25+
/** Creates a color ramp shader
26+
* @param colorRamp vector color ramp
27+
* @param colorRampType type of color ramp shader
28+
* @param classificationMode classification mode
29+
* @param classes number of classes
30+
* @param clip clip out of range values
31+
* @param extent extent used in classification (only used in quantile mode)
32+
*/
33+
void createShader( QgsColorRamp* colorRamp = nullptr, QgsColorRampShader::Type colorRampType = QgsColorRampShader::Interpolated, QgsColorRampShader::ClassificationMode classificationMode = QgsColorRampShader::Continuous, int classes = 0, bool clip = false, const QgsRectangle& extent = QgsRectangle() );
34+
2235
void writeXml( QDomDocument& doc, QDomElement& parentElem ) const;
2336

2437
void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;

python/gui/raster/qgssinglebandpseudocolorrendererwidget.sip

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ class QgsSingleBandPseudoColorRendererWidget : QgsRasterRendererWidget
55
%End
66

77
public:
8-
enum Mode
9-
{
10-
Continuous, // Using breaks from color palette
11-
EqualInterval,
12-
Quantile,
13-
};
148

159
QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent = QgsRectangle() );
1610
~QgsSingleBandPseudoColorRendererWidget();

0 commit comments

Comments
 (0)