QGIS API Documentation  2.99.0-Master (283d45a)
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 
28 #include "qgscolorramp.h"
29 #include "qgsrasterinterface.h"
31 #include "qgsrectangle.h"
32 
36 class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
37 {
38 
39  public:
40 
42  enum Type
43  {
46  Exact
47  };
48 
51  {
52  Continuous = 1,
53  EqualInterval = 2,
54  Quantile = 3
55  };
56 
65  QgsColorRampShader( double theMinimumValue = 0.0, double theMaximumValue = 255.0, QgsColorRamp* theColorRamp = nullptr, Type theType = Interpolated, ClassificationMode theClassificationMode = Continuous );
66 
69  QgsColorRampShader( const QgsColorRampShader& other );
70 
73  QgsColorRampShader& operator=( const QgsColorRampShader& other );
74 
75  //An entry for classification based upon value.
76  //Such a classification is typically used for
77  //single band layers where a pixel value represents
78  //not a color but a quantity, e.g. temperature or elevation
80  {
82  ColorRampItem() : value( 0 ) {}
84  ColorRampItem( double val, const QColor& col, const QString& lbl = QString() )
85  : label( lbl )
86  , value( val )
87  , color( col )
88  {}
89 
90  QString label;
91  double value;
92  QColor color;
93 
94  // compare operator for sorting
95  bool operator<( const ColorRampItem& other ) const { return value < other.value; }
96  };
97 
99  QList<QgsColorRampShader::ColorRampItem> colorRampItemList() const { return mColorRampItemList.toList(); }
100 
102  Type colorRampType() const { return mColorRampType; }
103 
105  QString colorRampTypeAsQString();
106 
108  void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList ); //TODO: sort on set
109 
111  void setColorRampType( QgsColorRampShader::Type theColorRampType );
112 
117  QgsColorRamp* sourceColorRamp() const;
118 
123  void setSourceColorRamp( QgsColorRamp* colorramp );
124 
126  void setColorRampType( const QString& theType );
127 
134  void classifyColorRamp( const int classes = 0, const int band = -1, const QgsRectangle& extent = QgsRectangle(), QgsRasterInterface* input = nullptr );
135 
141  void classifyColorRamp( const int band = -1, const QgsRectangle& extent = QgsRectangle(), QgsRasterInterface* input = nullptr );
142 
144  bool shade( double, int*, int*, int*, int* ) override;
145 
147  bool shade( double, double, double, double, int*, int*, int*, int* ) override;
148 
150  void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const override;
151 
153  void setClassificationMode( ClassificationMode classificationMode ) { mClassificationMode = classificationMode; }
154 
156  ClassificationMode classificationMode() const { return mClassificationMode; }
157 
162  void setClip( bool clip ) { mClip = clip; }
163 
167  bool clip() const { return mClip; }
168 
169  protected:
170 
172  QScopedPointer<QgsColorRamp> mSourceColorRamp;
173 
174  private:
175 
181  QVector<QgsColorRampShader::ColorRampItem> mColorRampItemList;
182 
183  Type mColorRampType;
184  ClassificationMode mClassificationMode;
185 
188  QVector<int> mLUT;
189  double mLUTOffset;
190  double mLUTFactor;
191  bool mLUTInitialized;
192 
194  bool mClip;
195 };
196 
197 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:36
QScopedPointer< QgsColorRamp > mSourceColorRamp
Source color ramp.
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.
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.