Class: QgsPalettedRasterRenderer

class qgis.core.QgsPalettedRasterRenderer

Bases: QgsRasterRenderer

Renderer for paletted raster images.

QgsPalettedRasterRenderer(input: QgsRasterInterface, bandNumber: int, classes: Iterable[QgsPalettedRasterRenderer.Class]) Constructor for QgsPalettedRasterRenderer.

Methods

accept

param visitor:

band

Returns the raster band used for rendering the raster.

block

param bandNo:

canCreateRasterAttributeTable

rtype:

bool

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.

classes

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

clone

QgsPalettedRasterRenderer cannot be copied.

colorTableToClassData

Converts a raster color table to paletted renderer class data.

create

param elem:

createLegendNodes

param nodeLayer:

flags

rtype:

Qgis.RasterRendererFlags

initHistogram

Fill in histogram defaults if not specified

initStatistics

Fill in statistics defaults if not specified

inputBand

rtype:

int

label

Returns optional category label

legendSymbologyItems

rtype:

List[Tuple[str, QColor]]

multiValueClasses

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

nColors

Returns number of colors

rasterAttributeTableToClassData

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

renderColorForNodataPixel

Returns the color for the renderer to use to represent nodata pixels.

setInputBand

param band:

setLabel

Set category label

setMultiValueClasses

Sets the multi value classes to setMultiValueClasses.

setSourceColorRamp

Set the source color ramp.

sourceColorRamp

Gets the source color ramp

toSld

param doc:

usesBands

rtype:

List[int]

writeXml

param doc:

class Class(value: float, color: QColor | Qt.GlobalColor | QGradient = QColor(), label: str = '')

Bases: sip.wrapper

Constructor for Class

QgsPalettedRasterRenderer.Class(QgsPalettedRasterRenderer.Class)

color
label
value
class MultiValueClass

Bases: sip.wrapper

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

New in version 3.30.

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

QgsPalettedRasterRenderer.MultiValueClass(QgsPalettedRasterRenderer.MultiValueClass)

color
label
values
accept(self, visitor: QgsStyleEntityVisitorInterface) bool
Parameters:

visitor (QgsStyleEntityVisitorInterface) –

Return type:

bool

band(self) int

Returns the raster band used for rendering the raster.

Deprecated since version QGIS: 3.38 use inputBand() instead

Return type:

int

block(self, bandNo: int, extent: QgsRectangle, width: int, height: int, feedback: QgsRasterBlockFeedback = None) QgsRasterBlock
Parameters:
Return type:

QgsRasterBlock

canCreateRasterAttributeTable(self) bool
Return type:

bool

classDataFromFile(path: str) List[QgsPalettedRasterRenderer.Class]

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

Parameters:

path (str) –

Return type:

List[QgsPalettedRasterRenderer.Class]

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

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]

classDataFromString(string: str) List[QgsPalettedRasterRenderer.Class]

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

Parameters:

string (str) –

Return type:

List[QgsPalettedRasterRenderer.Class]

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

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]

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

Return type:

List[QgsPalettedRasterRenderer.Class]

clone(self) QgsPalettedRasterRenderer

QgsPalettedRasterRenderer cannot be copied. Use clone() instead.

Return type:

QgsPalettedRasterRenderer

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

Converts a raster color table to paletted renderer class data.

Parameters:

table (Iterable[QgsColorRampShader.ColorRampItem]) –

Return type:

List[QgsPalettedRasterRenderer.Class]

create(elem: QDomElement, input: QgsRasterInterface) QgsRasterRenderer
Parameters:
Return type:

QgsRasterRenderer

createLegendNodes(self, nodeLayer: QgsLayerTreeLayer) List[QgsLayerTreeModelLegendNode]
Parameters:

nodeLayer (QgsLayerTreeLayer) –

Return type:

List[QgsLayerTreeModelLegendNode]

flags(self) Qgis.RasterRendererFlags
Return type:

Qgis.RasterRendererFlags

initHistogram(self, histogram: QgsRasterHistogram, bandNo: int, binCount: int, minimum: object = Py_None, maximum: object = Py_None, boundingBox: QgsRectangle = QgsRectangle(), sampleSize: int = 0, includeOutOfRange: bool = False)

Fill in histogram defaults if not specified

Note

the parameters are the same as in histogram()

initStatistics(self, statistics: QgsRasterBandStats, bandNo: int, stats: int, boundingBox: QgsRectangle = QgsRectangle(), binCount: int = 0)

Fill in statistics defaults if not specified

Deprecated since version Use: Qgis.RasterBandStatistic instead of int for stats argument

initStatistics(self, statistics: QgsRasterBandStats, bandNo: int, stats: Union[Qgis.RasterBandStatistics, Qgis.RasterBandStatistic] = Qgis.RasterBandStatistic.All, boundingBox: QgsRectangle = QgsRectangle(), binCount: int = 0) Fill in statistics defaults if not specified

inputBand(self) int
Return type:

int

label(self, idx: float) str

Returns optional category label

Parameters:

idx (float) –

Return type:

str

legendSymbologyItems(self) List[Tuple[str, QColor]]
Return type:

List[Tuple[str, QColor]]

multiValueClasses(self) List[QgsPalettedRasterRenderer.MultiValueClass]

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

New in version 3.30.

Return type:

List[QgsPalettedRasterRenderer.MultiValueClass]

nColors(self) int

Returns number of colors

Return type:

int

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

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.

New in version 3.30.

Parameters:
Return type:

List[QgsPalettedRasterRenderer.MultiValueClass]

renderColorForNodataPixel(self) int

Returns the color for the renderer to use to represent nodata pixels.

Subclasses should use this rather then nodataColor() to determine the color to use for nodata pixels during an actual rendering operation.

New in version 3.10.

setInputBand(self, band: int) bool
Parameters:

band (int) –

Return type:

bool

setLabel(self, idx: float, label: str)

Set category label

Parameters:
  • idx (float) –

  • label (str) –

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

Sets the multi value classes to setMultiValueClasses.

New in version 3.30.

Parameters:

classes (Iterable[QgsPalettedRasterRenderer.MultiValueClass]) –

setSourceColorRamp(self, ramp: QgsColorRamp)

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

Parameters:

ramp (QgsColorRamp) –

sourceColorRamp(self) QgsColorRamp

Gets the source color ramp

Return type:

QgsColorRamp

toSld(self, doc: QDomDocument, element: QDomElement, props: Dict[str, Any] = {})
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • props (Dict[str) –

usesBands(self) List[int]
Return type:

List[int]

writeXml(self, doc: QDomDocument, parentElem: QDomElement)
Parameters:
  • doc (QDomDocument) –

  • parentElem (QDomElement) –