QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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;
31
37{
38 public:
39
41 struct CORE_EXPORT Class
42 {
44 Class( double value, const QColor &color = QColor(), const QString &label = QString() )
45 : value( value )
46 , color( color )
47 , label( label )
48 {}
49
51 double value;
52
54 QColor color;
56 QString label;
57 };
58
64 class CORE_EXPORT MultiValueClass
65 {
66
67 public:
68
70 MultiValueClass( const QVector< QVariant > &values, const QColor &color = QColor(), const QString &label = QString() );
71
73 QVector< QVariant > values;
74
76 QColor color;
77
79 QString label;
80 };
81
82
84 typedef QList< QgsPalettedRasterRenderer::Class > ClassData;
85
87 typedef QList< QgsPalettedRasterRenderer::MultiValueClass > MultiValueClassData;
88
92 QgsPalettedRasterRenderer( QgsRasterInterface *input, int bandNumber, const ClassData &classes );
93
99
104
106 Qgis::RasterRendererFlags flags() const override;
107
108 static QgsRasterRenderer *create( const QDomElement &elem, QgsRasterInterface *input ) SIP_FACTORY;
109
110 QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
111
113 int nColors() const;
114
118 ClassData classes() const;
119
124 MultiValueClassData multiValueClasses( ) const;
125
126 bool canCreateRasterAttributeTable( ) const override;
127
132 void setMultiValueClasses( const MultiValueClassData &classes );
133
137 QString label( double idx ) const;
138
142 void setLabel( double idx, const QString &label );
143
149 Q_DECL_DEPRECATED int band() const SIP_DEPRECATED { return mBand; }
150
151 int inputBand() const override;
152 bool setInputBand( int band ) override;
153
154 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
155 QList< QPair< QString, QColor > > legendSymbologyItems() const override;
156 QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
157 QList<int> usesBands() const override;
158 void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override;
159 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
160
165 void setSourceColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
166
171 QgsColorRamp *sourceColorRamp() const;
172
176 static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );
177
186 static QgsPalettedRasterRenderer::MultiValueClassData rasterAttributeTableToClassData( const QgsRasterAttributeTable *attributeTable, int classificationColumn = -1, QgsColorRamp *ramp = nullptr );
187
194 static QgsPalettedRasterRenderer::ClassData classDataFromString( const QString &string );
195
200 static QgsPalettedRasterRenderer::ClassData classDataFromFile( const QString &path );
201
206 static QString classDataToString( const QgsPalettedRasterRenderer::ClassData &classes );
207
212 static QgsPalettedRasterRenderer::ClassData classDataFromRaster( QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp = nullptr,
213 QgsRasterBlockFeedback *feedback = nullptr );
214
215
216 private:
217#ifdef SIP_RUN
220#endif
221
222
223 int mBand;
224 MultiValueClassData mMultiValueClassData;
225
226 ClassData classData() const;
227
229 std::unique_ptr<QgsColorRamp> mSourceColorRamp;
230
232 QMap< double, QRgb > mColors;
233 void updateArrays();
234
235 // Maximum number of allowed classes for float rasters
236 static const int MAX_FLOAT_CLASSES;
237};
238
239#endif // QGSPALETTEDRASTERRENDERER_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
Abstract base class for color ramps.
Layer tree node points to a map layer.
Properties of a multi value class: a class that contains multiple values.
Renderer for paletted raster images.
const QgsPalettedRasterRenderer & operator=(const QgsPalettedRasterRenderer &)=delete
QgsPalettedRasterRenderer cannot be copied. Use clone() instead.
QList< QgsPalettedRasterRenderer::Class > ClassData
Map of value to class properties.
QList< QgsPalettedRasterRenderer::MultiValueClass > MultiValueClassData
Map of multi value to class properties.
QgsPalettedRasterRenderer(const QgsPalettedRasterRenderer &)=delete
QgsPalettedRasterRenderer cannot be copied. Use clone() instead.
QgsPalettedRasterRenderer(QgsRasterInterface *input, int bandNumber, const MultiValueClassData &classes)
Constructor for QgsPalettedRasterRenderer from multi value classes.
The QgsRasterAttributeTable class represents a Raster Attribute Table (RAT).
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 int inputBand() const
Returns the input band for the renderer, or -1 if no input band is available.
virtual bool setInputBand(int band)
Attempts to set the input band for the renderer.
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.
An interface for classes which can visit style entity (e.g.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76
Properties of a single value class.
Class(double value, const QColor &color=QColor(), const QString &label=QString())
Constructor for Class.