QGIS API Documentation  3.0.2-Girona (307d082)
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 
39 class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
40 {
41 
42  public:
43 
45  enum Type
46  {
49  Exact
50  };
51 
54  {
55  Continuous = 1,
56  EqualInterval = 2,
57  Quantile = 3
58  };
59 
69  QgsColorRampShader( double minimumValue = 0.0, double maximumValue = 255.0, QgsColorRamp *colorRamp = nullptr, Type type = Interpolated, ClassificationMode classificationMode = Continuous );
70 
74  QgsColorRampShader( const QgsColorRampShader &other );
75 
79  QgsColorRampShader &operator=( const QgsColorRampShader &other );
80 
81  //An entry for classification based upon value.
82  //Such a classification is typically used for
83  //single band layers where a pixel value represents
84  //not a color but a quantity, e.g. temperature or elevation
86  {
88  ColorRampItem() = default;
90  ColorRampItem( double val, const QColor &col, const QString &lbl = QString() )
91  : label( lbl )
92  , value( val )
93  , color( col )
94  {}
95 
96  QString label;
97  double value = 0;
98  QColor color;
99 
100  // compare operator for sorting
101  bool operator<( const QgsColorRampShader::ColorRampItem &other ) const { return value < other.value; }
102  };
103 
105  QList<QgsColorRampShader::ColorRampItem> colorRampItemList() const { return mColorRampItemList.toList(); }
106 
108  Type colorRampType() const { return mColorRampType; }
109 
111  QString colorRampTypeAsQString();
112 
114  void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem> &list ); //TODO: sort on set
115 
117  void setColorRampType( QgsColorRampShader::Type colorRampType );
118 
124  QgsColorRamp *sourceColorRamp() const SIP_FACTORY;
125 
131  void setSourceColorRamp( QgsColorRamp *colorramp SIP_TRANSFER );
132 
134  void setColorRampType( const QString &type );
135 
143  void classifyColorRamp( const int classes = 0, const int band = -1, const QgsRectangle &extent = QgsRectangle(), QgsRasterInterface *input = nullptr );
144 
151  void classifyColorRamp( const int band = -1, const QgsRectangle &extent = QgsRectangle(), QgsRasterInterface *input = nullptr ) SIP_PYNAME( classifyColorRampV2 );
152 
154  bool shade( double value, int *returnRedValue SIP_OUT, int *returnGreenValue SIP_OUT, int *returnBlueValue SIP_OUT, int *returnAlphaValue SIP_OUT ) override;
155 
157  bool shade( double redValue, double greenValue,
158  double blueValue, double alphaValue,
159  int *returnRedValue SIP_OUT, int *returnGreenValue SIP_OUT,
160  int *returnBlueValue SIP_OUT, int *returnAlphaValue SIP_OUT ) override;
161 
163  void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems SIP_OUT ) const override;
164 
166  void setClassificationMode( ClassificationMode classificationMode ) { mClassificationMode = classificationMode; }
167 
169  ClassificationMode classificationMode() const { return mClassificationMode; }
170 
176  void setClip( bool clip ) { mClip = clip; }
177 
182  bool clip() const { return mClip; }
183 
184  protected:
185 
187  std::unique_ptr<QgsColorRamp> mSourceColorRamp;
188 
189  private:
190 
197  QVector<QgsColorRampShader::ColorRampItem> mColorRampItemList;
198 
199  Type mColorRampType;
200  ClassificationMode mClassificationMode;
201 
205  QVector<int> mLUT;
206  double mLUTOffset = 0.0;
207  double mLUTFactor = 1.0;
208  bool mLUTInitialized = false;
209 
211  bool mClip = false;
212 };
213 
214 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:39
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:31
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:36
#define SIP_FACTORY
Definition: qgis_sip.h:69
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:51
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:74
bool operator<(const QgsColorRampShader::ColorRampItem &other) const