Class: QgsColorRampShader

class qgis.core.QgsColorRampShader(minimumValue: float = 0, maximumValue: float = 255, colorRamp: QgsColorRamp = None, type: QgsColorRampShader.Type = QgsColorRampShader.Interpolated, classificationMode: QgsColorRampShader.ClassificationMode = QgsColorRampShader.Continuous)

Bases: QgsRasterShaderFunction

Creates a new color ramp shader.

Parameters
  • minimumValue (float = 0) – minimum value for the raster shader

  • maximumValue (float = 255) – maximum value for the raster shader

  • type (QgsColorRampShader.Type = QgsColorRampShader.Interpolated) – interpolation type used

  • classificationMode (QgsColorRampShader.ClassificationMode = QgsColorRampShader.Continuous) – method used to classify the color ramp shader

  • colorRamp (QgsColorRamp = None) – vector color ramp used to classify the color ramp shader. Ownership is transferred to the shader.

Returns

new QgsColorRampShader

QgsColorRampShader(other: QgsColorRampShader) Copy constructor

A ramp shader will color a raster pixel based on a list of values ranges in a ramp.

Methods

classificationMode

Returns the classification mode

classifyColorRamp

Classify color ramp shader

classifyColorRampV2

Classify color ramp shader

clip

Returns whether the shader will clip values which are out of range.

colorRampItemList

Returns the custom colormap.

colorRampType

Returns the color ramp type.

colorRampTypeAsQString

Returns the color ramp type as a string.

isEmpty

Whether the color ramp contains any items

legendSymbologyItems

rtype

List[Tuple[str, QColor]]

readXml

Reads configuration from the given DOM element

setClassificationMode

Sets classification mode

setClip

Sets whether the shader should not render values out of range.

setColorRampItemList

param list

setColorRampType

Sets the color ramp type

setSourceColorRamp

Set the source color ramp.

shade

Generates and new RGB value based on one input value

sourceColorRamp

Returns the source color ramp.

writeXml

Writes configuration to a new DOM element

Attributes

Continuous

Discrete

EqualInterval

Exact

Interpolated

Quantile

class ClassificationMode

Bases: int

class ColorRampItem

Bases: sip.wrapper

default constructor

QgsColorRampShader.ColorRampItem(val: float, col: Union[QColor, Qt.GlobalColor, QGradient], lbl: str = ‘’) convenience constructor

QgsColorRampShader.ColorRampItem(QgsColorRampShader.ColorRampItem)

color
label
value
Continuous = 1
Discrete = 1
EqualInterval = 2
Exact = 2
Interpolated = 0
Quantile = 3
class Type

Bases: int

classificationMode(self) → QgsColorRampShader.ClassificationMode

Returns the classification mode

Return type

QgsColorRampShader.ClassificationMode

classifyColorRamp(self, classes: int = 0, band: int = -1, extent: QgsRectangle = QgsRectangle(), input: QgsRasterInterface = None)

Classify color ramp shader

Parameters
  • classes (int = 0) – number of classes

  • band (int = -1) – raster band used in classification (only used in quantile mode)

  • extent (QgsRectangle = QgsRectangle()) – extent used in classification (only used in quantile mode)

  • input (QgsRasterInterface = None) – raster input used in classification (only used in quantile mode)

classifyColorRampV2(self, band: int = -1, extent: QgsRectangle = QgsRectangle(), input: QgsRasterInterface = None)

Classify color ramp shader

Parameters
  • band (int = -1) – raster band used in classification (quantile mode only)

  • extent (QgsRectangle = QgsRectangle()) – extent used in classification (quantile mode only)

  • input (QgsRasterInterface = None) – raster input used in classification (quantile mode only)

clip(self) → bool

Returns whether the shader will clip values which are out of range.

See also

setClip()

Return type

bool

colorRampItemList(self) → List[QgsColorRampShader.ColorRampItem]

Returns the custom colormap.

Return type

List[QgsColorRampShader.ColorRampItem]

colorRampType(self) → QgsColorRampShader.Type

Returns the color ramp type.

Return type

QgsColorRampShader.Type

colorRampTypeAsQString(self) → str

Returns the color ramp type as a string.

Return type

str

isEmpty(self) → bool

Whether the color ramp contains any items

New in version 3.4.

Return type

bool

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

List[Tuple[str, QColor]]

readXml(self, elem: QDomElement)

Reads configuration from the given DOM element

New in version 3.4.

Parameters

elem (QDomElement) –

setClassificationMode(self, classificationMode: QgsColorRampShader.ClassificationMode)

Sets classification mode

Parameters

classificationMode (QgsColorRampShader.ClassificationMode) –

setClip(self, clip: bool)

Sets whether the shader should not render values out of range.

Parameters

clip (bool) – set to True to clip values which are out of range.

See also

clip()

setColorRampItemList(self, list: Iterable[QgsColorRampShader.ColorRampItem])
Parameters

list (Iterable[QgsColorRampShader.ColorRampItem]) –

setColorRampType(self, colorRampType: QgsColorRampShader.Type)

Sets the color ramp type

setColorRampType(self, type: str) Sets the color ramp type

Parameters

colorRampType (QgsColorRampShader.Type) –

setSourceColorRamp(self, colorramp: QgsColorRamp)

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

New in version 3.0.

Parameters

colorramp (QgsColorRamp) –

shade(self, value: float) → Tuple[bool, int, int, int, int]

Generates and new RGB value based on one input value

shade(self, redValue: float, greenValue: float, blueValue: float, alphaValue: float) -> Tuple[bool, int, int, int, int] Generates and new RGB value based on original RGB value

Parameters

value (float) –

Return type

Tuple[bool, int, int, int, int]

sourceColorRamp(self) → QgsColorRamp

Returns the source color ramp.

New in version 3.0.

Return type

QgsColorRamp

writeXml(self, doc: QDomDocument) → QDomElement

Writes configuration to a new DOM element

New in version 3.4.

Parameters

doc (QDomDocument) –

Return type

QDomElement