Class: QgsColorRampShader

class qgis.core.QgsColorRampShader

Bases: QgsRasterShaderFunction

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

QgsColorRampShader(minimumValue: float = 0, maximumValue: float = 255, colorRamp: Optional[QgsColorRamp] = None, type: Qgis.ShaderInterpolationMethod = Qgis.ShaderInterpolationMethod.Linear, classificationMode: Qgis.ShaderClassificationMethod = Qgis.ShaderClassificationMethod.Continuous) Creates a new color ramp shader.

Parameters:
  • minimumValue – minimum value for the raster shader

  • maximumValue – maximum value for the raster shader

  • type – interpolation type used

  • classificationMode – method used to classify the color ramp shader

  • colorRamp – vector color ramp used to classify the color ramp shader. Ownership is transferred to the shader.

QgsColorRampShader(other: QgsColorRampShader) Copy constructor

Enums

ClassificationMode

alias of ShaderClassificationMethod

Type

alias of ShaderInterpolationMethod

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 color map.

colorRampType

Returns the color ramp interpolation method.

colorRampTypeAsQString

Returns the color ramp type as a string.

createColorRamp

Creates a gradient color ramp from shader settings.

isEmpty

Whether the color ramp contains any items

legendSettings

Returns the color ramp shader legend settings.

legendSymbologyItems

rtype:

List[Tuple[str, QColor]]

readXml

Reads configuration from the given DOM element

setClassificationMode

Sets the classification mode.

setClip

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

setColorRampItemList

param list:

setColorRampType

Sets the color ramp interpolation method.

setLegendSettings

Sets the color ramp shader legend settings.

setSourceColorRamp

Set the source color ramp.

shade

param value:

sourceColorRamp

Returns the source color ramp.

writeXml

Writes configuration to a new DOM element

ClassificationMode

alias of ShaderClassificationMethod

class ColorRampItem

Bases: sip.wrapper

default constructor

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

QgsColorRampShader.ColorRampItem(a0: QgsColorRampShader.ColorRampItem)

color
label
value
Type

alias of ShaderInterpolationMethod

classificationMode(self) Qgis.ShaderClassificationMethod

Returns the classification mode.

Return type:

Qgis.ShaderClassificationMethod

classifyColorRamp(self, classes: int = 0, band: int = -1, extent: QgsRectangle = QgsRectangle(), input: QgsRasterInterface | None = 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 (Optional[QgsRasterInterface] = None) – raster input used in classification (only used in quantile mode)

classifyColorRampV2(self, band: int = -1, extent: QgsRectangle = QgsRectangle(), input: QgsRasterInterface | None = 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 (Optional[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 color map.

Return type:

List[QgsColorRampShader.ColorRampItem]

colorRampType(self) Qgis.ShaderInterpolationMethod

Returns the color ramp interpolation method.

Return type:

Qgis.ShaderInterpolationMethod

colorRampTypeAsQString(self) str

Returns the color ramp type as a string.

Return type:

str

createColorRamp(self) QgsColorRamp | None

Creates a gradient color ramp from shader settings.

Added in version 3.18.

Return type:

Optional[QgsColorRamp]

isEmpty(self) bool

Whether the color ramp contains any items

Added in version 3.4.

Return type:

bool

legendSettings(self) QgsColorRampLegendNodeSettings | None

Returns the color ramp shader legend settings.

Added in version 3.18.

Return type:

Optional[QgsColorRampLegendNodeSettings]

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

List[Tuple[str, QColor]]

readXml(self, elem: QDomElement, context: QgsReadWriteContext = QgsReadWriteContext())

Reads configuration from the given DOM element

Added in version 3.4.

Parameters:
setClassificationMode(self, classificationMode: Qgis.ShaderClassificationMethod)

Sets the classification mode.

Parameters:

classificationMode (Qgis.ShaderClassificationMethod)

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: Qgis.ShaderInterpolationMethod)

Sets the color ramp interpolation method.

See also

colorRampType()

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

Parameters:

colorRampType (Qgis.ShaderInterpolationMethod)

setLegendSettings(self, settings: QgsColorRampLegendNodeSettings | None)

Sets the color ramp shader legend settings.

Ownership of settings is transferred.

See also

legendSettings()

Added in version 3.18.

Parameters:

settings (Optional[QgsColorRampLegendNodeSettings])

setSourceColorRamp(self, colorramp: QgsColorRamp | None)

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

Parameters:

colorramp (Optional[QgsColorRamp])

shade(self, value: float)
shade(self, redValue: float, greenValue: float, blueValue: float, alphaValue: float) None
Parameters:

value (float) -> (bool)

sourceColorRamp(self) QgsColorRamp | None

Returns the source color ramp.

Return type:

Optional[QgsColorRamp]

writeXml(self, doc: QDomDocument, context: QgsReadWriteContext = QgsReadWriteContext()) QDomElement

Writes configuration to a new DOM element

Added in version 3.4.

Parameters:
Return type:

QDomElement