QgsColorRampShader class

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

Base classes

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

Public types

enum ClassificationMode { Continuous = 1, EqualInterval = 2, Quantile = 3 }
Classification modes used to create the color ramp shader.
enum Type { Interpolated, Discrete, Exact }
Supported methods for color interpolation.

Constructors, destructors, conversion operators

QgsColorRampShader(double minimumValue = 0.0, double maximumValue = 255.0, QgsColorRamp* colorRamp = nullptr, Type type = Interpolated, ClassificationMode classificationMode = Continuous)
Creates a new color ramp shader.
QgsColorRampShader(const QgsColorRampShader& other)
Copy constructor.

Public functions

auto classificationMode() const -> ClassificationMode
Returns the classification mode.
void classifyColorRamp(int classes = 0, int band = -1, const QgsRectangle& extent = QgsRectangle(), QgsRasterInterface* input = nullptr)
Classify color ramp shader.
void classifyColorRamp(int band = -1, const QgsRectangle& extent = QgsRectangle(), QgsRasterInterface* input = nullptr)
Classify color ramp shader.
auto clip() const -> bool
Returns whether the shader will clip values which are out of range.
auto colorRampItemList() const -> QList<QgsColorRampShader::ColorRampItem>
Returns the custom colormap.
auto colorRampType() const -> Type
Returns the color ramp type.
auto colorRampTypeAsQString() const -> QString
Returns the color ramp type as a string.
auto isEmpty() const -> bool
Whether the color ramp contains any items.
void legendSymbologyItems(QList<QPair<QString, QColor>>& symbolItems) const override
Returns legend symbology items if provided by renderer.
auto operator=(const QgsColorRampShader& other) -> QgsColorRampShader&
Assignment operator.
void readXml(const QDomElement& elem)
Reads configuration from the given DOM element.
void setClassificationMode(ClassificationMode classificationMode)
Sets classification mode.
void setClip(bool clip)
Sets whether the shader should not render values out of range.
void setColorRampItemList(const QList<QgsColorRampShader::ColorRampItem>& list)
Sets a custom colormap.
void setColorRampType(QgsColorRampShader::Type colorRampType)
Sets the color ramp type.
void setColorRampType(const QString& type)
Sets the color ramp type.
void setSourceColorRamp(QgsColorRamp* colorramp)
Set the source color ramp.
auto shade(double value, int* returnRedValue, int* returnGreenValue, int* returnBlueValue, int* returnAlphaValue) const -> bool override
Generates and new RGB value based on one input value.
auto shade(double redValue, double greenValue, double blueValue, double alphaValue, int* returnRedValue, int* returnGreenValue, int* returnBlueValue, int* returnAlphaValue) const -> bool override
Generates and new RGB value based on original RGB value.
auto sourceColorRamp() const -> QgsColorRamp*
Gets the source color ramp.
auto writeXml(QDomDocument& doc) const -> QDomElement
Writes configuration to a new DOM element.

Protected variables

std::unique_ptr<QgsColorRamp> mSourceColorRamp
Source color ramp.

Enum documentation

enum QgsColorRampShader::ClassificationMode

Classification modes used to create the color ramp shader.

Enumerators
Continuous

Uses breaks from color palette.

EqualInterval

Uses equal interval.

Quantile

Uses quantile (i.e. equal pixel) count.

enum QgsColorRampShader::Type

Supported methods for color interpolation.

Enumerators
Interpolated

Interpolates the color between two class breaks linearly.

Discrete

Assigns the color of the higher class for every pixel between two class breaks.

Exact

Assigns the color of the exact matching value in the color ramp item list.

Function documentation

QgsColorRampShader::QgsColorRampShader(double minimumValue = 0.0, double maximumValue = 255.0, QgsColorRamp* colorRamp = nullptr, Type type = Interpolated, ClassificationMode classificationMode = Continuous)

Creates a new color ramp shader.

Parameters
minimumValue minimum value for the raster shader
maximumValue maximum value for the raster shader
colorRamp vector color ramp used to classify the color ramp shader. Ownership is transferred to the shader.
type interpolation type used
classificationMode method used to classify the color ramp shader
Returns new QgsColorRampShader

void QgsColorRampShader::classifyColorRamp(int classes = 0, int band = -1, const QgsRectangle& extent = QgsRectangle(), QgsRasterInterface* input = nullptr)

Classify color ramp shader.

Parameters
classes number of classes
band raster band used in classification (only used in quantile mode)
extent extent used in classification (only used in quantile mode)
input raster input used in classification (only used in quantile mode)

void QgsColorRampShader::classifyColorRamp(int band = -1, const QgsRectangle& extent = QgsRectangle(), QgsRasterInterface* input = nullptr)

Classify color ramp shader.

Parameters
band raster band used in classification (quantile mode only)
extent extent used in classification (quantile mode only)
input raster input used in classification (quantile mode only)

bool QgsColorRampShader::clip() const

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

bool QgsColorRampShader::isEmpty() const

Whether the color ramp contains any items.

void QgsColorRampShader::readXml(const QDomElement& elem)

Reads configuration from the given DOM element.

void QgsColorRampShader::setClip(bool clip)

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

Parameters
clip set to true to clip values which are out of range.

void QgsColorRampShader::setSourceColorRamp(QgsColorRamp* colorramp)

Set the source color ramp.

Ownership is transferred to the shader.

QgsColorRamp* QgsColorRampShader::sourceColorRamp() const

Gets the source color ramp.

QDomElement QgsColorRampShader::writeXml(QDomDocument& doc) const

Writes configuration to a new DOM element.