QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
138 QString label( double idx ) const;
139
144 void setLabel( double idx, const QString &label );
145
150 int band() const { return mBand; }
151
152 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
153 QList< QPair< QString, QColor > > legendSymbologyItems() const override;
154 QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
155 QList<int> usesBands() const override;
156 void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override;
157 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
158
164 void setSourceColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
165
171 QgsColorRamp *sourceColorRamp() const;
172
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
196 static QgsPalettedRasterRenderer::ClassData classDataFromString( const QString &string );
197
203 static QgsPalettedRasterRenderer::ClassData classDataFromFile( const QString &path );
204
210 static QString classDataToString( const QgsPalettedRasterRenderer::ClassData &classes );
211
217 static QgsPalettedRasterRenderer::ClassData classDataFromRaster( QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp = nullptr,
218 QgsRasterBlockFeedback *feedback = nullptr );
219
220
221 private:
222#ifdef SIP_RUN
225#endif
226
227
228 int mBand;
229 MultiValueClassData mMultiValueClassData;
230
231 ClassData classData() const;
232
234 std::unique_ptr<QgsColorRamp> mSourceColorRamp;
235
237 QMap< double, QRgb > mColors;
238 void updateArrays();
239
240 // Maximum number of allowed classes for float rasters
241 static const int MAX_FLOAT_CLASSES;
242};
243
244#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 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_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.