QGIS API Documentation  3.6.0-Noosa (5873452)
qgspalettedrasterrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspalettedrasterrenderer.h
3  ---------------------------
4  begin : December 2011
5  copyright : (C) 2011 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSPALETTEDRASTERRENDERER_H
19 #define QGSPALETTEDRASTERRENDERER_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include <QVector>
24 
25 #include "qgsrasterrenderer.h"
26 #include "qgscolorrampshader.h"
27 
28 class QColor;
29 class QDomElement;
30 
36 {
37  public:
38 
40  struct Class
41  {
43  Class( int value, const QColor &color = QColor(), const QString &label = QString() )
44  : value( value )
45  , color( color )
46  , label( label )
47  {}
48 
50  int value;
51 
53  QColor color;
55  QString label;
56  };
57 
59  typedef QList< QgsPalettedRasterRenderer::Class > ClassData;
60 
64  QgsPalettedRasterRenderer( QgsRasterInterface *input, int bandNumber, const ClassData &classes );
65 
69  const QgsPalettedRasterRenderer &operator=( const QgsPalettedRasterRenderer & ) = delete;
70 
71  QgsPalettedRasterRenderer *clone() const override SIP_FACTORY;
72  static QgsRasterRenderer *create( const QDomElement &elem, QgsRasterInterface *input ) SIP_FACTORY;
73 
74  QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
75 
77  int nColors() const { return mClassData.size(); }
78 
82  ClassData classes() const;
83 
87  QString label( int idx ) const;
88 
92  void setLabel( int idx, const QString &label );
93 
98  int band() const { return mBand; }
99 
100  void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
101 
102  void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems SIP_OUT ) const override;
103 
104  QList<int> usesBands() const override;
105 
106  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const override;
107 
113  void setSourceColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
114 
120  QgsColorRamp *sourceColorRamp() const;
121 
126  static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );
127 
134  static QgsPalettedRasterRenderer::ClassData classDataFromString( const QString &string );
135 
141  static QgsPalettedRasterRenderer::ClassData classDataFromFile( const QString &path );
142 
148  static QString classDataToString( const QgsPalettedRasterRenderer::ClassData &classes );
149 
155  static QgsPalettedRasterRenderer::ClassData classDataFromRaster( QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp = nullptr,
156  QgsRasterBlockFeedback *feedback = nullptr );
157 
158  private:
159 #ifdef SIP_RUN
161  const QgsPalettedRasterRenderer &operator=( const QgsPalettedRasterRenderer & );
162 #endif
163 
164 
165  int mBand;
166  ClassData mClassData;
167 
169  std::unique_ptr<QgsColorRamp> mSourceColorRamp;
170 
172  QMap< int, QRgb > mColors;
173  void updateArrays();
174 };
175 
176 #endif // QGSPALETTEDRASTERRENDERER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QColor color
Color to render value.
Renderer for paletted raster images.
Abstract base class for color ramps.
Definition: qgscolorramp.h:31
Properties of a single value class.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:587
Raster data container.
QList< QgsPalettedRasterRenderer::Class > ClassData
Map of value to class properties.
#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.
#define SIP_OUT
Definition: qgis_sip.h:51
int band() const
Returns the raster band used for rendering the raster.
Class(int value, const QColor &color=QColor(), const QString &label=QString())
Constructor for Class.
Feedback object tailored for raster block reading.
Raster renderer pipe that applies colors to a raster.