QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
40 struct CORE_EXPORT 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
63 class CORE_EXPORT MultiValueClass
64 {
65 public:
67 MultiValueClass( const QVector< QVariant > &values, const QColor &color = QColor(), const QString &label = QString() );
68
70 QVector< QVariant > values;
71
73 QColor color;
74
76 QString label;
77 };
78
79
81 typedef QList< QgsPalettedRasterRenderer::Class > ClassData;
82
84 typedef QList< QgsPalettedRasterRenderer::MultiValueClass > MultiValueClassData;
85
90
96
101
103 Qgis::RasterRendererFlags flags() const override;
104
105 static QgsRasterRenderer *create( const QDomElement &elem, QgsRasterInterface *input ) SIP_FACTORY;
106
107 QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
108
110 int nColors() const;
111
115 ClassData classes() const;
116
122
123 bool canCreateRasterAttributeTable() const override;
124
130
134 QString label( double idx ) const;
135
139 void setLabel( double idx, const QString &label );
140
146 Q_DECL_DEPRECATED int band() const SIP_DEPRECATED { return mBand; }
147
148 int inputBand() const override;
149 bool setInputBand( int band ) override;
150
151 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
152 QList< QPair< QString, QColor > > legendSymbologyItems() const override;
153 QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
154 QList<int> usesBands() const override;
155 Q_DECL_DEPRECATED void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override SIP_DEPRECATED;
156 bool toSld( QDomDocument &doc, QDomElement &element, QgsSldExportContext &context ) const override;
157 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
158
163 void setSourceColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
164
169 QgsColorRamp *sourceColorRamp() const;
170
174 static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );
175
184 static QgsPalettedRasterRenderer::MultiValueClassData rasterAttributeTableToClassData( const QgsRasterAttributeTable *attributeTable, int classificationColumn = -1, QgsColorRamp *ramp = nullptr );
185
192 static QgsPalettedRasterRenderer::ClassData classDataFromString( const QString &string );
193
198 static QgsPalettedRasterRenderer::ClassData classDataFromFile( const QString &path );
199
204 static QString classDataToString( const QgsPalettedRasterRenderer::ClassData &classes );
205
210 static QgsPalettedRasterRenderer::ClassData classDataFromRaster( QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp = nullptr, QgsRasterBlockFeedback *feedback = nullptr );
211
212
213 private:
214#ifdef SIP_RUN
217#endif
218
219
220 int mBand;
221 MultiValueClassData mMultiValueClassData;
222
223 ClassData classData() const;
224
226 std::unique_ptr<QgsColorRamp> mSourceColorRamp;
227
229 QMap< double, QRgb > mColors;
230 void updateArrays();
231
232 // Maximum number of allowed classes for float rasters
233 static const int MAX_FLOAT_CLASSES;
234};
235
236#endif // QGSPALETTEDRASTERRENDERER_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
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:113
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
Class(double value, const QColor &color=QColor(), const QString &label=QString())
Constructor for Class.