Class: QgsPalettedRasterRenderer

Renderer for paletted raster images.

Class Hierarchy

Inheritance diagram of qgis.core.QgsPalettedRasterRenderer

Base classes

QgsRasterRenderer

Raster renderer pipe that applies colors to a raster.

QgsRasterInterface

Base class for processing filters like renderers, reprojector, resampler etc.

Methods

band

Returns the raster band used for rendering the raster.

classes

Returns a map of value to classes (colors) used by the renderer.

label

Returns optional category label

multiValueClasses

Returns a map of multi value to classes (colors) used by the renderer.

nColors

Returns number of colors

setLabel

Set category label

setMultiValueClasses

Sets the multi value classes to setMultiValueClasses.

setSourceColorRamp

Set the source color ramp.

sourceColorRamp

Gets the source color ramp

Static Methods

classDataFromFile

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

classDataFromRaster

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

classDataFromString

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

classDataToString

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

colorTableToClassData

Converts a raster color table to paletted renderer class data.

create

rasterAttributeTableToClassData

Reads and returns classes from the Raster Attribute Table attributeTable, optionally classifying the attribute table by classificationColumn and setting the colors from ramp.

class qgis.core.QgsPalettedRasterRenderer[source]

Bases: QgsRasterRenderer

__init__(input: QgsRasterInterface | None, bandNumber: int, classes: Iterable[QgsPalettedRasterRenderer.Class])

Constructor for QgsPalettedRasterRenderer.

Parameters:
class Class

Bases: object

Properties of a single value class

color: QColor

Color to render value

label: str

Label for value

value: float

Value

class MultiValueClass[source]

Bases: object

Properties of a multi value class: a class that contains multiple values.

Added in version 3.30.

QgsPalettedRasterRenderer.MultiValueClass(values: Iterable[Any], color: Union[QColor, Qt.GlobalColor] = QColor(), label: Optional[str] = ‘’) Constructor for MultiValueClass from a list of values

QgsPalettedRasterRenderer.MultiValueClass(a0: QgsPalettedRasterRenderer.MultiValueClass)

color: QColor

Color to render values

label: str

Label for values

values: List[object]

Values

band(self) int[source]

Returns the raster band used for rendering the raster.

Deprecated since version 3.38: Use inputBand() instead.

Return type:

int

static classDataFromFile(path: str | None) List[QgsPalettedRasterRenderer.Class][source]

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

Parameters:

path (Optional[str])

Return type:

List[QgsPalettedRasterRenderer.Class]

static classDataFromRaster(raster: QgsRasterInterface | None, bandNumber: int, ramp: QgsColorRamp | None = None, feedback: QgsRasterBlockFeedback | None = None) List[QgsPalettedRasterRenderer.Class][source]

Generates class data from a raster, for the specified bandNumber. An optional color ramp can be specified to automatically assign colors from the ramp.

Parameters:
Return type:

List[QgsPalettedRasterRenderer.Class]

static classDataFromString(string: str | None) List[QgsPalettedRasterRenderer.Class][source]

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

Parameters:

string (Optional[str])

Return type:

List[QgsPalettedRasterRenderer.Class]

static classDataToString(classes: Iterable[QgsPalettedRasterRenderer.Class]) str[source]

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

Parameters:

classes (Iterable[QgsPalettedRasterRenderer.Class])

Return type:

str

classes(self) List[QgsPalettedRasterRenderer.Class][source]

Returns a map of value to classes (colors) used by the renderer.

Return type:

List[QgsPalettedRasterRenderer.Class]

static colorTableToClassData(table: Iterable[QgsColorRampShader.ColorRampItem]) List[QgsPalettedRasterRenderer.Class][source]

Converts a raster color table to paletted renderer class data.

Parameters:

table (Iterable[QgsColorRampShader.ColorRampItem])

Return type:

List[QgsPalettedRasterRenderer.Class]

static create(elem: QDomElement, input: QgsRasterInterface | None) QgsRasterRenderer | None[source]
Parameters:
Return type:

Optional[QgsRasterRenderer]

label(self, idx: float) str[source]

Returns optional category label

Parameters:

idx (float)

Return type:

str

multiValueClasses(self) List[QgsPalettedRasterRenderer.MultiValueClass][source]

Returns a map of multi value to classes (colors) used by the renderer.

Added in version 3.30.

Return type:

List[QgsPalettedRasterRenderer.MultiValueClass]

nColors(self) int[source]

Returns number of colors

Return type:

int

static rasterAttributeTableToClassData(attributeTable: QgsRasterAttributeTable | None, classificationColumn: int = -1, ramp: QgsColorRamp | None = None) List[QgsPalettedRasterRenderer.MultiValueClass][source]

Reads and returns classes from the Raster Attribute Table attributeTable, optionally classifying the attribute table by classificationColumn and setting the colors from ramp. The default value of -1 for the classificationColumn uses the first available value column.

Note

The method will return an empty list of classes in case the Raster Attribute Table is not thematic.

Added in version 3.30.

Parameters:
Return type:

List[QgsPalettedRasterRenderer.MultiValueClass]

setLabel(self, idx: float, label: str | None)[source]

Set category label

Parameters:
  • idx (float)

  • label (Optional[str])

setMultiValueClasses(self, classes: Iterable[QgsPalettedRasterRenderer.MultiValueClass])[source]

Sets the multi value classes to setMultiValueClasses.

Added in version 3.30.

Parameters:

classes (Iterable[QgsPalettedRasterRenderer.MultiValueClass])

setSourceColorRamp(self, ramp: QgsColorRamp | None)[source]

Set the source color ramp. Ownership is transferred to the renderer.

Parameters:

ramp (Optional[QgsColorRamp])

sourceColorRamp(self) QgsColorRamp | None[source]

Gets the source color ramp

Return type:

Optional[QgsColorRamp]