QGIS API Documentation  2.99.0-Master (9f5e33a)
qgscolorrampshader.h
Go to the documentation of this file.
1 /* **************************************************************************
2  qgscolorrampshader.h - description
3  -------------------
4 begin : Fri Dec 28 2007
5 copyright : (C) 2007 by Peter J. Ersts
6 email : [email protected]
7 
8 This class is based off of code that was originally written by Marco Hugentobler and
9 originally part of the larger QgsRasterLayer class
10 ****************************************************************************/
11 
12 /* **************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  ***************************************************************************/
20 
21 #ifndef QGSCOLORRAMPSHADER_H
22 #define QGSCOLORRAMPSHADER_H
23 
24 #include "qgis_core.h"
25 #include "qgis.h"
26 #include <QColor>
27 #include <QVector>
28 #include <memory>
29 
30 #include "qgscolorramp.h"
31 #include "qgsrasterinterface.h"
33 #include "qgsrectangle.h"
34 
38 class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
39 {
40 
41  public:
42 
44  enum Type
45  {
48  Exact
49  };
50 
53  {
54  Continuous = 1,
55  EqualInterval = 2,
56  Quantile = 3
57  };
58 
67  QgsColorRampShader( double minimumValue = 0.0, double maximumValue = 255.0, QgsColorRamp *colorRamp = nullptr, Type type = Interpolated, ClassificationMode classificationMode = Continuous );
68 
71  QgsColorRampShader( const QgsColorRampShader &other );
72 
75  QgsColorRampShader &operator=( const QgsColorRampShader &other );
76 
77  //An entry for classification based upon value.
78  //Such a classification is typically used for
79  //single band layers where a pixel value represents
80  //not a color but a quantity, e.g. temperature or elevation
82  {
84  ColorRampItem() : value( 0 ) {}
86  ColorRampItem( double val, const QColor &col, const QString &lbl = QString() )
87  : label( lbl )
88  , value( val )
89  , color( col )
90  {}
91 
92  QString label;
93  double value;
94  QColor color;
95 
96  // compare operator for sorting
97  bool operator<( const QgsColorRampShader::ColorRampItem &other ) const { return value < other.value; }
98  };
99 
101  QList<QgsColorRampShader::ColorRampItem> colorRampItemList() const { return mColorRampItemList.toList(); }
102 
104  Type colorRampType() const { return mColorRampType; }
105 
107  QString colorRampTypeAsQString();
108 
110  void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem> &list ); //TODO: sort on set
111 
113  void setColorRampType( QgsColorRampShader::Type colorRampType );
114 
119  QgsColorRamp *sourceColorRamp() const SIP_FACTORY;
120 
125  void setSourceColorRamp( QgsColorRamp *colorramp SIP_TRANSFER );
126 
128  void setColorRampType( const QString &type );
129 
136  void classifyColorRamp( const int classes = 0, const int band = -1, const QgsRectangle &extent = QgsRectangle(), QgsRasterInterface *input = nullptr );
137 
143  void classifyColorRamp( const int band = -1, const QgsRectangle &extent = QgsRectangle(), QgsRasterInterface *input = nullptr ) SIP_PYNAME( classifyColorRampV2 );
144 
146  bool shade( double value, int *returnRedValue SIP_OUT, int *returnGreenValue SIP_OUT, int *returnBlueValue SIP_OUT, int *returnAlphaValue SIP_OUT ) override;
147 
149  bool shade( double redValue, double greenValue,
150  double blueValue, double alphaValue,
151  int *returnRedValue SIP_OUT, int *returnGreenValue SIP_OUT,
152  int *returnBlueValue SIP_OUT, int *returnAlphaValue SIP_OUT ) override;
153 
155  void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems SIP_OUT ) const override;
156 
158  void setClassificationMode( ClassificationMode classificationMode ) { mClassificationMode = classificationMode; }
159 
161  ClassificationMode classificationMode() const { return mClassificationMode; }
162 
167  void setClip( bool clip ) { mClip = clip; }
168 
172  bool clip() const { return mClip; }
173 
174  protected:
175 
177  std::unique_ptr<QgsColorRamp> mSourceColorRamp;
178 
179  private:
180 
186  QVector<QgsColorRampShader::ColorRampItem> mColorRampItemList;
187 
188  Type mColorRampType;
189  ClassificationMode mClassificationMode;
190 
193  QVector<int> mLUT;
194  double mLUTOffset;
195  double mLUTFactor;
196  bool mLUTInitialized;
197 
199  bool mClip;
200 };
201 
202 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:38
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Abstract base class for color ramps.
Definition: qgscolorramp.h:30
QList< QgsColorRampShader::ColorRampItem > colorRampItemList() const
Get the custom colormap.
void setClip(bool clip)
Sets whether the shader should not render values out of range.
Type
Supported methods for color interpolation.
The raster shade function applies a shader to a pixel at render time - typically used to render grays...
ColorRampItem(double val, const QColor &col, const QString &lbl=QString())
convenience constructor
#define SIP_TRANSFER
Definition: qgis_sip.h:24
#define SIP_FACTORY
Definition: qgis_sip.h:57
Base class for processing filters like renderers, reprojector, resampler etc.
Type colorRampType() const
Get the color ramp type.
std::unique_ptr< QgsColorRamp > mSourceColorRamp
Source color ramp.
#define SIP_OUT
Definition: qgis_sip.h:39
void setClassificationMode(ClassificationMode classificationMode)
Sets classification mode.
bool clip() const
Returns whether the shader will clip values which are out of range.
Interpolates the color between two class breaks linearly.
ClassificationMode
Classification modes used to create the color ramp shader.
Assigns the color of the higher class for every pixel between two class breaks.
ClassificationMode classificationMode() const
Returns the classification mode.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:62
bool operator<(const QgsColorRampShader::ColorRampItem &other) const