QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
28class QColor;
29class 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 Qgis::RasterRendererFlags flags() const override;
73
74 static QgsRasterRenderer *create( const QDomElement &elem, QgsRasterInterface *input ) SIP_FACTORY;
75
76 QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
77
79 int nColors() const { return mClassData.size(); }
80
84 ClassData classes() const;
85
90 QString label( double idx ) const;
91
96 void setLabel( double idx, const QString &label );
97
102 int band() const { return mBand; }
103
104 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
105 QList< QPair< QString, QColor > > legendSymbologyItems() const override;
106 QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
107 QList<int> usesBands() const override;
108 void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override;
109 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
110
116 void setSourceColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
117
123 QgsColorRamp *sourceColorRamp() const;
124
129 static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );
130
137 static QgsPalettedRasterRenderer::ClassData classDataFromString( const QString &string );
138
144 static QgsPalettedRasterRenderer::ClassData classDataFromFile( const QString &path );
145
151 static QString classDataToString( const QgsPalettedRasterRenderer::ClassData &classes );
152
158 static QgsPalettedRasterRenderer::ClassData classDataFromRaster( QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp = nullptr,
159 QgsRasterBlockFeedback *feedback = nullptr );
160
161 private:
162#ifdef SIP_RUN
165#endif
166
167
168 int mBand;
169 ClassData mClassData;
170
172 std::unique_ptr<QgsColorRamp> mSourceColorRamp;
173
175 QMap< double, QRgb > mColors;
176 void updateArrays();
177
178 // Maximum number of allowed classes for float rasters
179 static const int MAX_FLOAT_CLASSES;
180};
181
182#endif // QGSPALETTEDRASTERRENDERER_H
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:72
Abstract base class for color ramps.
Definition: qgscolorramp.h:30
Layer tree node points to a map layer.
Renderer for paletted raster images.
const QgsPalettedRasterRenderer & operator=(const QgsPalettedRasterRenderer &)=delete
QgsPalettedRasterRenderer cannot be copied. Use clone() instead.
int band() const
Returns the raster band used for rendering the raster.
QList< QgsPalettedRasterRenderer::Class > ClassData
Map of value to class properties.
QgsPalettedRasterRenderer(const QgsPalettedRasterRenderer &)=delete
QgsPalettedRasterRenderer cannot be copied. Use clone() instead.
Feedback object tailored for raster block reading.
Raster data container.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Write base class members to xml.
Raster renderer pipe that applies colors to a raster.
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
virtual QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer)
Creates a set of legend nodes representing the renderer.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
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.
virtual QList< QPair< QString, QColor > > legendSymbologyItems() const
Returns symbology items if provided by renderer.
const QgsRasterRenderer & operator=(const QgsRasterRenderer &)=delete
QgsRasterRenderer cannot be copied. Use clone() instead.
QgsRasterRenderer * clone() const override=0
Clone itself, create deep copy.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
An interface for classes which can visit style entity (e.g.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
Properties of a single value class.
QColor color
Color to render value.
Class(double value, const QColor &color=QColor(), const QString &label=QString())
Constructor for Class.