QgsPalettedRasterRenderer class

Renderer for paletted raster images.

Base classes

class QgsRasterRenderer
Raster renderer pipe that applies colors to a raster.

Public types

struct Class
Properties of a single value class.
using ClassData = QList<QgsPalettedRasterRenderer::Class>
Map of value to class properties.

Public static functions

static auto classDataFromFile(const QString& path) -> QgsPalettedRasterRenderer::ClassData
Opens a color table file and returns corresponding paletted renderer class data.
static auto classDataFromRaster(QgsRasterInterface* raster, int bandNumber, QgsColorRamp* ramp = nullptr, QgsRasterBlockFeedback* feedback = nullptr) -> QgsPalettedRasterRenderer::ClassData
Generates class data from a raster, for the specified bandNumber.
static auto classDataFromString(const QString& string) -> QgsPalettedRasterRenderer::ClassData
Converts a string containing a color table or class data to to paletted renderer class data.
static auto classDataToString(const QgsPalettedRasterRenderer::ClassData& classes) -> QString
Converts classes to a string representation, using the .clr/gdal color table file format.
static auto colorTableToClassData(const QList<QgsColorRampShader::ColorRampItem>& table) -> QgsPalettedRasterRenderer::ClassData
Converts a raster color table to paletted renderer class data.

Constructors, destructors, conversion operators

QgsPalettedRasterRenderer(QgsRasterInterface* input, int bandNumber, const ClassData& classes)
Constructor for QgsPalettedRasterRenderer.
QgsPalettedRasterRenderer(const QgsPalettedRasterRenderer&) deleted
QgsPalettedRasterRenderer cannot be copied. Use clone() instead.

Public functions

auto band() const -> int
Returns the raster band used for rendering the raster.
auto block(int bandNo, const QgsRectangle& extent, int width, int height, QgsRasterBlockFeedback* feedback = nullptr) -> QgsRasterBlock* override
Read block of data using given extent and size.
auto classes() const -> ClassData
Returns a map of value to classes (colors) used by the renderer.
auto clone() const -> QgsPalettedRasterRenderer* override
Clone itself, create deep copy.
auto label(int idx) const -> QString
Returns optional category label.
void legendSymbologyItems(QList<QPair<QString, QColor>>& symbolItems) const override
Gets symbology items if provided by renderer.
auto nColors() const -> int
Returns number of colors.
auto operator=(const QgsPalettedRasterRenderer&) -> const QgsPalettedRasterRenderer& deleted
QgsPalettedRasterRenderer cannot be copied. Use clone() instead.
void setLabel(int idx, const QString& label)
Set category label.
void setSourceColorRamp(QgsColorRamp* ramp)
Set the source color ramp.
auto sourceColorRamp() const -> QgsColorRamp*
Gets the source color ramp.
auto usesBands() const -> QList<int> override
Returns a list of band numbers used by the renderer.
void writeXml(QDomDocument& doc, QDomElement& parentElem) const override
Write base class members to xml.

Function documentation

static QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromFile(const QString& path)

Opens a color table file and returns corresponding paletted renderer class data.

static QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromRaster(QgsRasterInterface* raster, int bandNumber, QgsColorRamp* ramp = nullptr, QgsRasterBlockFeedback* feedback = nullptr)

Generates class data from a raster, for the specified bandNumber.

An optional color ramp can be specified to automatically assign colors from the ramp.

static QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromString(const QString& string)

Converts a string containing a color table or class data to to paletted renderer class data.

static QString QgsPalettedRasterRenderer::classDataToString(const QgsPalettedRasterRenderer::ClassData& classes)

Converts classes to a string representation, using the .clr/gdal color table file format.

static QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::colorTableToClassData(const QList<QgsColorRampShader::ColorRampItem>& table)

Converts a raster color table to paletted renderer class data.

int QgsPalettedRasterRenderer::band() const

Returns the raster band used for rendering the raster.

QgsRasterBlock* QgsPalettedRasterRenderer::block(int bandNo, const QgsRectangle& extent, int width, int height, QgsRasterBlockFeedback* feedback = nullptr) override

Read block of data using given extent and size.

Parameters
bandNo band number
extent extent of block
width pixel width of block
height pixel height of block
feedback optional raster feedback object for cancelation/preview. Added in QGIS 3.0.

Returns pointer to data. Caller is responsible to free the memory returned.

QString QgsPalettedRasterRenderer::label(int idx) const

Returns optional category label.

void QgsPalettedRasterRenderer::setLabel(int idx, const QString& label)

Set category label.

void QgsPalettedRasterRenderer::setSourceColorRamp(QgsColorRamp* ramp)

Set the source color ramp.

Ownership is transferred to the renderer.

QgsColorRamp* QgsPalettedRasterRenderer::sourceColorRamp() const

Gets the source color ramp.