QGIS API Documentation  3.4.15-Madeira (e83d02e274)
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
QgsColorRampShader Class Reference

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

#include <qgscolorrampshader.h>

Inheritance diagram for QgsColorRampShader:
Inheritance graph
[legend]

Classes

struct  ColorRampItem
 

Public Types

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

Public Member Functions

 QgsColorRampShader (double minimumValue=0.0, double maximumValue=255.0, QgsColorRamp *colorRamp=nullptr, Type type=Interpolated, ClassificationMode classificationMode=Continuous)
 Creates a new color ramp shader. More...
 
 QgsColorRampShader (const QgsColorRampShader &other)
 Copy constructor. More...
 
ClassificationMode classificationMode () const
 Returns the classification mode. More...
 
void classifyColorRamp (int classes=0, int band=-1, const QgsRectangle &extent=QgsRectangle(), QgsRasterInterface *input=nullptr)
 Classify color ramp shader. More...
 
void classifyColorRamp (int band=-1, const QgsRectangle &extent=QgsRectangle(), QgsRasterInterface *input=nullptr)
 Classify color ramp shader. More...
 
bool clip () const
 Returns whether the shader will clip values which are out of range. More...
 
QList< QgsColorRampShader::ColorRampItemcolorRampItemList () const
 Returns the custom colormap. More...
 
Type colorRampType () const
 Returns the color ramp type. More...
 
QString colorRampTypeAsQString () const
 Returns the color ramp type as a string. More...
 
bool isEmpty () const
 Whether the color ramp contains any items. More...
 
void legendSymbologyItems (QList< QPair< QString, QColor > > &symbolItems) const override
 Returns legend symbology items if provided by renderer. More...
 
QgsColorRampShaderoperator= (const QgsColorRampShader &other)
 Assignment operator. More...
 
void readXml (const QDomElement &elem)
 Reads configuration from the given DOM element. More...
 
void setClassificationMode (ClassificationMode classificationMode)
 Sets classification mode. More...
 
void setClip (bool clip)
 Sets whether the shader should not render values out of range. More...
 
void setColorRampItemList (const QList< QgsColorRampShader::ColorRampItem > &list)
 Sets a custom colormap. More...
 
void setColorRampType (QgsColorRampShader::Type colorRampType)
 Sets the color ramp type. More...
 
void setColorRampType (const QString &type)
 Sets the color ramp type. More...
 
void setSourceColorRamp (QgsColorRamp *colorramp)
 Set the source color ramp. More...
 
bool shade (double value, int *returnRedValue, int *returnGreenValue, int *returnBlueValue, int *returnAlphaValue) const override
 Generates and new RGB value based on one input value. More...
 
bool shade (double redValue, double greenValue, double blueValue, double alphaValue, int *returnRedValue, int *returnGreenValue, int *returnBlueValue, int *returnAlphaValue) const override
 Generates and new RGB value based on original RGB value. More...
 
QgsColorRampsourceColorRamp () const
 Returns the source color ramp. More...
 
QDomElement writeXml (QDomDocument &doc) const
 Writes configuration to a new DOM element. More...
 
- Public Member Functions inherited from QgsRasterShaderFunction
 QgsRasterShaderFunction (double minimumValue=0.0, double maximumValue=255.0)
 
virtual ~QgsRasterShaderFunction ()=default
 
double maximumValue () const
 Returns the minimum value for the raster shader. More...
 
double minimumMaximumRange () const
 
double minimumValue () const
 Returns the maximum value for the raster shader. More...
 
virtual void setMaximumValue (double value)
 Sets the maximum value for the raster shader. More...
 
virtual void setMinimumValue (double value)
 Sets the minimum value for the raster shader. More...
 

Protected Attributes

std::unique_ptr< QgsColorRampmSourceColorRamp
 Source color ramp. More...
 
- Protected Attributes inherited from QgsRasterShaderFunction
double mMaximumValue
 User defineable maximum value for the shading function. More...
 
double mMinimumMaximumRange
 Minimum maximum range for the shading function. More...
 
double mMinimumValue
 User defineable minimum value for the shading function. More...
 

Detailed Description

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

Definition at line 39 of file qgscolorrampshader.h.

Member Enumeration Documentation

Classification modes used to create the color ramp shader.

Enumerator
Continuous 

Uses breaks from color palette.

EqualInterval 

Uses equal interval.

Quantile 

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

Definition at line 53 of file qgscolorrampshader.h.

Supported methods for color interpolation.

Enumerator
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.

Definition at line 45 of file qgscolorrampshader.h.

Constructor & Destructor 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
minimumValueminimum value for the raster shader
maximumValuemaximum value for the raster shader
typeinterpolation type used
classificationModemethod used to classify the color ramp shader
colorRampvector color ramp used to classify the color ramp shader. Ownership is transferred to the shader.
Returns
new QgsColorRampShader

Definition at line 34 of file qgscolorrampshader.cpp.

QgsColorRampShader::QgsColorRampShader ( const QgsColorRampShader other)

Copy constructor.

Definition at line 44 of file qgscolorrampshader.cpp.

Member Function Documentation

ClassificationMode QgsColorRampShader::classificationMode ( ) const
inline

Returns the classification mode.

Definition at line 187 of file qgscolorrampshader.h.

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

Classify color ramp shader.

Parameters
classesnumber of classes
bandraster band used in classification (only used in quantile mode)
extentextent used in classification (only used in quantile mode)
inputraster input used in classification (only used in quantile mode)

Definition at line 135 of file qgscolorrampshader.cpp.

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

Classify color ramp shader.

Parameters
bandraster band used in classification (quantile mode only)
extentextent used in classification (quantile mode only)
inputraster input used in classification (quantile mode only)

Definition at line 314 of file qgscolorrampshader.cpp.

bool QgsColorRampShader::clip ( ) const
inline

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

See also
setClip()

Definition at line 200 of file qgscolorrampshader.h.

QList<QgsColorRampShader::ColorRampItem> QgsColorRampShader::colorRampItemList ( ) const
inline

Returns the custom colormap.

Definition at line 105 of file qgscolorrampshader.h.

Type QgsColorRampShader::colorRampType ( ) const
inline

Returns the color ramp type.

Definition at line 108 of file qgscolorrampshader.h.

QString QgsColorRampShader::colorRampTypeAsQString ( ) const

Returns the color ramp type as a string.

Definition at line 77 of file qgscolorrampshader.cpp.

bool QgsColorRampShader::isEmpty ( ) const

Whether the color ramp contains any items.

Since
QGIS 3.4

Definition at line 104 of file qgscolorrampshader.cpp.

void QgsColorRampShader::legendSymbologyItems ( QList< QPair< QString, QColor > > &  symbolItems) const
overridevirtual

Returns legend symbology items if provided by renderer.

Reimplemented from QgsRasterShaderFunction.

Definition at line 487 of file qgscolorrampshader.cpp.

QgsColorRampShader & QgsColorRampShader::operator= ( const QgsColorRampShader other)

Assignment operator.

Definition at line 59 of file qgscolorrampshader.cpp.

void QgsColorRampShader::readXml ( const QDomElement &  elem)

Reads configuration from the given DOM element.

Since
QGIS 3.4

Definition at line 525 of file qgscolorrampshader.cpp.

void QgsColorRampShader::setClassificationMode ( ClassificationMode  classificationMode)
inline

Sets classification mode.

Definition at line 184 of file qgscolorrampshader.h.

void QgsColorRampShader::setClip ( bool  clip)
inline

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

Parameters
clipset to true to clip values which are out of range.
See also
clip()

Definition at line 194 of file qgscolorrampshader.h.

void QgsColorRampShader::setColorRampItemList ( const QList< QgsColorRampShader::ColorRampItem > &  list)

Sets a custom colormap.

Definition at line 91 of file qgscolorrampshader.cpp.

void QgsColorRampShader::setColorRampType ( QgsColorRampShader::Type  colorRampType)

Sets the color ramp type.

Definition at line 99 of file qgscolorrampshader.cpp.

void QgsColorRampShader::setColorRampType ( const QString &  type)

Sets the color ramp type.

Definition at line 109 of file qgscolorrampshader.cpp.

void QgsColorRampShader::setSourceColorRamp ( QgsColorRamp colorramp)

Set the source color ramp.

Ownership is transferred to the shader.

See also
sourceColorRamp()
Since
QGIS 3.0

Definition at line 130 of file qgscolorrampshader.cpp.

bool QgsColorRampShader::shade ( double  value,
int *  returnRedValue,
int *  returnGreenValue,
int *  returnBlueValue,
int *  returnAlphaValue 
) const
overridevirtual

Generates and new RGB value based on one input value.

Reimplemented from QgsRasterShaderFunction.

Definition at line 319 of file qgscolorrampshader.cpp.

bool QgsColorRampShader::shade ( double  redValue,
double  greenValue,
double  blueValue,
double  alphaValue,
int *  returnRedValue,
int *  returnGreenValue,
int *  returnBlueValue,
int *  returnAlphaValue 
) const
overridevirtual

Generates and new RGB value based on original RGB value.

Reimplemented from QgsRasterShaderFunction.

Definition at line 469 of file qgscolorrampshader.cpp.

QgsColorRamp * QgsColorRampShader::sourceColorRamp ( ) const

Returns the source color ramp.

See also
setSourceColorRamp()
Since
QGIS 3.0

Definition at line 125 of file qgscolorrampshader.cpp.

QDomElement QgsColorRampShader::writeXml ( QDomDocument &  doc) const

Writes configuration to a new DOM element.

Since
QGIS 3.4

Definition at line 496 of file qgscolorrampshader.cpp.

Member Data Documentation

std::unique_ptr<QgsColorRamp> QgsColorRampShader::mSourceColorRamp
protected

Source color ramp.

Definition at line 205 of file qgscolorrampshader.h.


The documentation for this class was generated from the following files: