Class: QgsColorRampShader

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

Class Hierarchy

Inheritance diagram of qgis.core.QgsColorRampShader

Base classes

QgsRasterShaderFunction

The raster shade function applies a shader to a pixel at render time - typically used to render grayscale images as false color.

class qgis.core.QgsColorRampShader[source]

Bases: QgsRasterShaderFunction

__init__(minimumValue: float = 0, maximumValue: float = 255, colorRamp: QgsColorRamp | None = None, type: Qgis.ShaderInterpolationMethod = Qgis.ShaderInterpolationMethod.Linear, classificationMode: Qgis.ShaderClassificationMethod = Qgis.ShaderClassificationMethod.Continuous)

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 (Qgis.ShaderInterpolationMethod = Qgis.ShaderInterpolationMethod.Linear) – interpolation type used

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

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

__init__(other: QgsColorRampShader)
Parameters:

other (QgsColorRampShader)

ClassificationMode

alias of ShaderClassificationMethod

class ColorRampItem

Bases: object

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[source]

Returns the classification mode.

Return type:

Qgis.ShaderClassificationMethod

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

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[source]

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[source]

Returns the color ramp interpolation method.

Return type:

Qgis.ShaderInterpolationMethod

colorRampTypeAsQString(self) str[source]

Returns the color ramp type as a string.

Return type:

str

createColorRamp(self) QgsColorRamp | None[source]

Creates a gradient color ramp from shader settings.

Added in version 3.18.

Return type:

Optional[QgsColorRamp]

isEmpty(self) bool[source]

Whether the color ramp contains any items

Added in version 3.4.

Return type:

bool

legendSettings(self) QgsColorRampLegendNodeSettings | None[source]

Returns the color ramp shader legend settings.

Added in version 3.18.

Return type:

Optional[QgsColorRampLegendNodeSettings]

readXml(self, elem: QDomElement, context: QgsReadWriteContext = QgsReadWriteContext())[source]

Reads configuration from the given DOM element

Added in version 3.4.

Parameters:
setClassificationMode(self, classificationMode: Qgis.ShaderClassificationMethod)[source]

Sets the classification mode.

Parameters:

classificationMode (Qgis.ShaderClassificationMethod)

setClip(self, clip: bool)[source]

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])[source]
Parameters:

list (Iterable[QgsColorRampShader.ColorRampItem])

setColorRampType(self, colorRampType: Qgis.ShaderInterpolationMethod)[source]

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)[source]

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)[source]

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

Parameters:

colorramp (Optional[QgsColorRamp])

sourceColorRamp(self) QgsColorRamp | None[source]

Returns the source color ramp.

Return type:

Optional[QgsColorRamp]

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

Writes configuration to a new DOM element

Added in version 3.4.

Parameters:
Return type:

QDomElement