QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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( double value, const QColor &color = QColor(), const QString &label = QString() )
44  : value( value )
45  , color( color )
46  , label( label )
47  {}
48 
50  double 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 
70 
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 
88  QString label( double idx ) const;
89 
94  void setLabel( double idx, const QString &label );
95 
100  int band() const { return mBand; }
101 
102  void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
103  QList< QPair< QString, QColor > > legendSymbologyItems() const override;
104  QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
105  QList<int> usesBands() const override;
106  void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override;
107  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
108 
114  void setSourceColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
115 
121  QgsColorRamp *sourceColorRamp() const;
122 
127  static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );
128 
135  static QgsPalettedRasterRenderer::ClassData classDataFromString( const QString &string );
136 
142  static QgsPalettedRasterRenderer::ClassData classDataFromFile( const QString &path );
143 
149  static QString classDataToString( const QgsPalettedRasterRenderer::ClassData &classes );
150 
156  static QgsPalettedRasterRenderer::ClassData classDataFromRaster( QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp = nullptr,
157  QgsRasterBlockFeedback *feedback = nullptr );
158 
159  private:
160 #ifdef SIP_RUN
163 #endif
164 
165 
166  int mBand;
167  ClassData mClassData;
168 
170  std::unique_ptr<QgsColorRamp> mSourceColorRamp;
171 
173  QMap< double, QRgb > mColors;
174  void updateArrays();
175 
176  // Maximum number of allowed classes for float rasters
177  static const int MAX_FLOAT_CLASSES;
178 };
179 
180 #endif // QGSPALETTEDRASTERRENDERER_H
QgsPalettedRasterRenderer::ClassData
QList< QgsPalettedRasterRenderer::Class > ClassData
Map of value to class properties.
Definition: qgspalettedrasterrenderer.h:59
QgsPalettedRasterRenderer::Class::Class
Class(double value, const QColor &color=QColor(), const QString &label=QString())
Constructor for Class.
Definition: qgspalettedrasterrenderer.h:43
QgsColorRamp
Abstract base class for color ramps.
Definition: qgscolorramp.h:29
QgsRasterRenderer::legendSymbologyItems
virtual QList< QPair< QString, QColor > > legendSymbologyItems() const
Returns symbology items if provided by renderer.
Definition: qgsrasterrenderer.cpp:105
QgsRasterInterface::writeXml
virtual void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Write base class members to xml.
Definition: qgsrasterinterface.h:494
QgsPalettedRasterRenderer::Class::color
QColor color
Color to render value.
Definition: qgspalettedrasterrenderer.h:53
QgsRasterRenderer::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Definition: qgsrasterrenderer.cpp:223
QgsPalettedRasterRenderer::Class::label
QString label
Label for value.
Definition: qgspalettedrasterrenderer.h:55
qgscolorrampshader.h
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
qgsrasterrenderer.h
QgsRasterRenderer::usesBands
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
Definition: qgsrasterrenderer.h:151
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsPalettedRasterRenderer::Class::value
double value
Value.
Definition: qgspalettedrasterrenderer.h:50
QgsRasterRenderer
Raster renderer pipe that applies colors to a raster.
Definition: qgsrasterrenderer.h:40
QgsLayerTreeLayer
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:43
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsPalettedRasterRenderer::band
int band() const
Returns the raster band used for rendering the raster.
Definition: qgspalettedrasterrenderer.h:100
QgsRasterRenderer::toSld
virtual void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
Used from subclasses to create SLD Rule elements following SLD v1.0 specs.
Definition: qgsrasterrenderer.cpp:209
QgsPalettedRasterRenderer::Class
Properties of a single value class.
Definition: qgspalettedrasterrenderer.h:40
QgsPalettedRasterRenderer
Renderer for paletted raster images.
Definition: qgspalettedrasterrenderer.h:35
QgsRasterRenderer::clone
QgsRasterRenderer * clone() const override=0
Clone itself, create deep copy.
QgsRasterInterface
Base class for processing filters like renderers, reprojector, resampler etc.
Definition: qgsrasterinterface.h:135
QgsRasterBlockFeedback
Feedback object tailored for raster block reading.
Definition: qgsrasterinterface.h:41
QgsRasterRenderer::operator=
const QgsRasterRenderer & operator=(const QgsRasterRenderer &)=delete
QgsRasterRenderer cannot be copied. Use clone() instead.
QgsRasterRenderer::createLegendNodes
virtual QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer)
Creates a set of legend nodes representing the renderer.
Definition: qgsrasterrenderer.cpp:110
QgsRasterBlock
Raster data container.
Definition: qgsrasterblock.h:36