QGIS API Documentation  2.99.0-Master (b8fd1fd)
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 <QColor>
26 #include <QVector>
27 #include <memory>
28 
29 #include "qgscolorramp.h"
30 #include "qgsrasterinterface.h"
32 #include "qgsrectangle.h"
33 
37 class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
38 {
39 
40  public:
41 
43  enum Type
44  {
47  Exact
48  };
49 
52  {
53  Continuous = 1,
54  EqualInterval = 2,
55  Quantile = 3
56  };
57 
66  QgsColorRampShader( double minimumValue = 0.0, double maximumValue = 255.0, QgsColorRamp *colorRamp = nullptr, Type type = Interpolated, ClassificationMode classificationMode = Continuous );
67 
70  QgsColorRampShader( const QgsColorRampShader &other );
71 
74  QgsColorRampShader &operator=( const QgsColorRampShader &other );
75 
76  //An entry for classification based upon value.
77  //Such a classification is typically used for
78  //single band layers where a pixel value represents
79  //not a color but a quantity, e.g. temperature or elevation
81  {
83  ColorRampItem() : value( 0 ) {}
85  ColorRampItem( double val, const QColor &col, const QString &lbl = QString() )
86  : label( lbl )
87  , value( val )
88  , color( col )
89  {}
90 
91  QString label;
92  double value;
93  QColor color;
94 
95  // compare operator for sorting
96  bool operator<( const ColorRampItem &other ) const { return value < other.value; }
97  };
98 
100  QList<QgsColorRampShader::ColorRampItem> colorRampItemList() const { return mColorRampItemList.toList(); }
101 
103  Type colorRampType() const { return mColorRampType; }
104 
106  QString colorRampTypeAsQString();
107 
109  void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem> &list ); //TODO: sort on set
110 
112  void setColorRampType( QgsColorRampShader::Type colorRampType );
113 
118  QgsColorRamp *sourceColorRamp() const;
119 
124  void setSourceColorRamp( QgsColorRamp *colorramp );
125 
127  void setColorRampType( const QString &type );
128 
135  void classifyColorRamp( const int classes = 0, const int band = -1, const QgsRectangle &extent = QgsRectangle(), QgsRasterInterface *input = nullptr );
136 
142  void classifyColorRamp( const int band = -1, const QgsRectangle &extent = QgsRectangle(), QgsRasterInterface *input = nullptr );
143 
145  bool shade( double, int *, int *, int *, int * ) override;
146 
148  bool shade( double, double, double, double, int *, int *, int *, int * ) override;
149 
151  void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems ) const override;
152 
154  void setClassificationMode( ClassificationMode classificationMode ) { mClassificationMode = classificationMode; }
155 
157  ClassificationMode classificationMode() const { return mClassificationMode; }
158 
163  void setClip( bool clip ) { mClip = clip; }
164 
168  bool clip() const { return mClip; }
169 
170  protected:
171 
173  std::unique_ptr<QgsColorRamp> mSourceColorRamp;
174 
175  private:
176 
182  QVector<QgsColorRampShader::ColorRampItem> mColorRampItemList;
183 
184  Type mColorRampType;
185  ClassificationMode mClassificationMode;
186 
189  QVector<int> mLUT;
190  double mLUTOffset;
191  double mLUTFactor;
192  bool mLUTInitialized;
193 
195  bool mClip;
196 };
197 
198 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:36
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
bool operator<(const ColorRampItem &other) const
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.
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.