QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 "qgscolorrampshader.h"
24#include "qgsrasterrenderer.h"
25
26#include <QVector>
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
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
125
126 bool canCreateRasterAttributeTable( ) const override;
127
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 Q_DECL_DEPRECATED void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override SIP_DEPRECATED;
159 bool toSld( QDomDocument &doc, QDomElement &element, QgsSldExportContext &context ) const override;
160 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
161
166 void setSourceColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
167
172 QgsColorRamp *sourceColorRamp() const;
173
177 static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );
178
187 static QgsPalettedRasterRenderer::MultiValueClassData rasterAttributeTableToClassData( const QgsRasterAttributeTable *attributeTable, int classificationColumn = -1, QgsColorRamp *ramp = nullptr );
188
195 static QgsPalettedRasterRenderer::ClassData classDataFromString( const QString &string );
196
201 static QgsPalettedRasterRenderer::ClassData classDataFromFile( const QString &path );
202
207 static QString classDataToString( const QgsPalettedRasterRenderer::ClassData &classes );
208
213 static QgsPalettedRasterRenderer::ClassData classDataFromRaster( QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp = nullptr,
214 QgsRasterBlockFeedback *feedback = nullptr );
215
216
217 private:
218#ifdef SIP_RUN
221#endif
222
223
224 int mBand;
225 MultiValueClassData mMultiValueClassData;
226
227 ClassData classData() const;
228
230 std::unique_ptr<QgsColorRamp> mSourceColorRamp;
231
233 QMap< double, QRgb > mColors;
234 void updateArrays();
235
236 // Maximum number of allowed classes for float rasters
237 static const int MAX_FLOAT_CLASSES;
238};
239
240#endif // QGSPALETTEDRASTERRENDERER_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Abstract base class for color ramps.
Layer tree node points to a map layer.
MultiValueClass(const QVector< QVariant > &values, const QColor &color=QColor(), const QString &label=QString())
Constructor for MultiValueClass from a list of values.
Renderer for paletted raster images.
const QgsPalettedRasterRenderer & operator=(const QgsPalettedRasterRenderer &)=delete
QgsPalettedRasterRenderer cannot be copied. Use clone() instead.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
QString label(double idx) const
Returns optional category label.
bool canCreateRasterAttributeTable() const override
Returns true if the renderer is suitable for attribute table creation.
Q_DECL_DEPRECATED int band() const
Returns the raster band used for rendering the raster.
QList< QgsPalettedRasterRenderer::Class > ClassData
Map of value to class properties.
Qgis::RasterRendererFlags flags() const override
Returns flags which dictate renderer behavior.
int nColors() const
Returns number of colors.
QList< QgsPalettedRasterRenderer::MultiValueClass > MultiValueClassData
Map of multi value to class properties.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
void setMultiValueClasses(const MultiValueClassData &classes)
Sets the multi value classes to setMultiValueClasses.
QgsPalettedRasterRenderer(const QgsPalettedRasterRenderer &)=delete
QgsPalettedRasterRenderer cannot be copied. Use clone() instead.
ClassData classes() const
Returns a map of value to classes (colors) used by the renderer.
QgsPalettedRasterRenderer(QgsRasterInterface *input, int bandNumber, const MultiValueClassData &classes)
Constructor for QgsPalettedRasterRenderer from multi value classes.
void setLabel(double idx, const QString &label)
Set category label.
MultiValueClassData multiValueClasses() const
Returns a map of multi value to classes (colors) used by the renderer.
QgsPalettedRasterRenderer(QgsRasterInterface *input, int bandNumber, const ClassData &classes)
Constructor for QgsPalettedRasterRenderer.
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.
QgsRasterInterface(QgsRasterInterface *input=nullptr)
virtual QgsRectangle extent() const
Gets the extent of the interface.
virtual void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Write base class members to xml.
virtual QgsRasterInterface * input() const
Current input.
QgsRasterRenderer(QgsRasterInterface *input=nullptr, const QString &type=QString())
Constructor for QgsRasterRenderer.
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 Q_DECL_DEPRECATED 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.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
An interface for classes which can visit style entity (e.g.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
Class(double value, const QColor &color=QColor(), const QString &label=QString())
Constructor for Class.