QGIS API Documentation  3.37.0-Master (a5b4d9743e8)
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
QgsRasterRenderer Class Referenceabstract

Raster renderer pipe that applies colors to a raster. More...

#include <qgsrasterrenderer.h>

Inheritance diagram for QgsRasterRenderer:
Inheritance graph
[legend]

Public Member Functions

 QgsRasterRenderer (const QgsRasterRenderer &)=delete
 QgsRasterRenderer cannot be copied. Use clone() instead. More...
 
 QgsRasterRenderer (QgsRasterInterface *input=nullptr, const QString &type=QString())
 Constructor for QgsRasterRenderer. More...
 
 ~QgsRasterRenderer () override
 
virtual bool accept (QgsStyleEntityVisitorInterface *visitor) const
 Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer. More...
 
int alphaBand () const
 
int bandCount () const override
 Gets number of bands. More...
 
QgsRasterBlockblock (int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override=0
 Read block of data using given extent and size. More...
 
virtual bool canCreateRasterAttributeTable () const
 Returns true if the renderer is suitable for attribute table creation. More...
 
QgsRasterRendererclone () const override=0
 Clone itself, create deep copy. More...
 
void copyCommonProperties (const QgsRasterRenderer *other, bool copyMinMaxOrigin=true)
 Copies common properties like opacity / transparency data from other renderer. More...
 
virtual QList< QgsLayerTreeModelLegendNode * > createLegendNodes (QgsLayerTreeLayer *nodeLayer)
 Creates a set of legend nodes representing the renderer. More...
 
Qgis::DataType dataType (int bandNo) const override
 Returns data type for the band specified by number. More...
 
virtual Qgis::RasterRendererFlags flags () const
 Returns flags which dictate renderer behavior. More...
 
virtual int inputBand () const
 Returns the input band for the renderer, or -1 if no input band is available. More...
 
virtual QList< QPair< QString, QColor > > legendSymbologyItems () const
 Returns symbology items if provided by renderer. More...
 
const QgsRasterMinMaxOriginminMaxOrigin () const
 Returns const reference to origin of min/max values. More...
 
QColor nodataColor () const
 Returns the color to use for shading nodata pixels. More...
 
double opacity () const
 Returns the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque). More...
 
const QgsRasterRendereroperator= (const QgsRasterRenderer &)=delete
 QgsRasterRenderer cannot be copied. Use clone() instead. More...
 
const QgsRasterTransparencyrasterTransparency () const
 
void readXml (const QDomElement &rendererElem) override
 Sets base class members from xml. Usually called from create() methods of subclasses. More...
 
void setAlphaBand (int band)
 
bool setInput (QgsRasterInterface *input) override
 Set input. More...
 
virtual bool setInputBand (int band)
 Attempts to set the input band for the renderer. More...
 
void setMinMaxOrigin (const QgsRasterMinMaxOrigin &origin)
 Sets origin of min/max values. More...
 
void setNodataColor (const QColor &color)
 Sets the color to use for shading nodata pixels. More...
 
void setOpacity (double opacity)
 Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque). More...
 
void setRasterTransparency (QgsRasterTransparency *t)
 
virtual void toSld (QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
 Used from subclasses to create SLD Rule elements following SLD v1.0 specs. More...
 
virtual QString type () const
 Returns a unique string representation of the renderer type. More...
 
virtual QList< int > usesBands () const
 Returns a list of band numbers used by the renderer. More...
 
bool usesTransparency () const
 
- Public Member Functions inherited from QgsRasterInterface
 QgsRasterInterface (QgsRasterInterface *input=nullptr)
 
virtual ~QgsRasterInterface ()=default
 
Q_DECL_DEPRECATED QgsRasterBandStats bandStatistics (int bandNo, int stats, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, QgsRasterBlockFeedback *feedback=nullptr)
 Returns the band statistics. More...
 
virtual QgsRasterBandStats bandStatistics (int bandNo, Qgis::RasterBandStatistics stats=Qgis::RasterBandStatistic::All, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, QgsRasterBlockFeedback *feedback=nullptr)
 Returns the band statistics. More...
 
virtual int capabilities () const
 Returns a bitmask containing the supported capabilities. More...
 
QString capabilitiesString () const
 Returns the raster interface capabilities in friendly format. More...
 
virtual QString colorInterpretationName (int bandNumber) const
 Returns the name of the color interpretation for the specified bandNumber. More...
 
virtual void cumulativeCut (int bandNo, double lowerCount, double upperCount, double &lowerValue, double &upperValue, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0)
 Find values for cumulative pixel count cut. More...
 
int dataTypeSize (int bandNo) const
 Returns the size (in bytes) for the data type for the specified band. More...
 
QString displayBandName (int bandNumber) const
 Generates a friendly, descriptive name for the specified bandNumber. More...
 
virtual QgsRectangle extent () const
 Gets the extent of the interface. More...
 
virtual QString generateBandName (int bandNumber) const
 helper function to create zero padded band names More...
 
virtual bool hasHistogram (int bandNo, int binCount, double minimum=std::numeric_limits< double >::quiet_NaN(), double maximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, bool includeOutOfRange=false)
 Returns true if histogram is available (cached, already calculated) More...
 
Q_DECL_DEPRECATED bool hasStatistics (int bandNo, int stats, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0)
 Returns true if histogram is available (cached, already calculated). More...
 
virtual bool hasStatistics (int bandNo, Qgis::RasterBandStatistics stats=Qgis::RasterBandStatistic::All, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0)
 Returns true if histogram is available (cached, already calculated). More...
 
virtual QgsRasterHistogram histogram (int bandNo, int binCount=0, double minimum=std::numeric_limits< double >::quiet_NaN(), double maximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, bool includeOutOfRange=false, QgsRasterBlockFeedback *feedback=nullptr)
 Returns a band histogram. More...
 
virtual QgsRasterInterfaceinput () const
 Current input. More...
 
virtual bool on () const
 Returns whether the interface is on or off. More...
 
virtual void setOn (bool on)
 Sets whether the interface is on or off. More...
 
virtual Qgis::DataType sourceDataType (int bandNo) const
 Returns source data type for the band specified by number, source data type may be shorter than dataType. More...
 
virtual QgsRasterInterfacesourceInput ()
 Gets source / raw input, the first in pipe, usually provider. More...
 
virtual const QgsRasterInterfacesourceInput () const
 Gets source / raw input, the first in pipe, usually provider. More...
 
virtual void writeXml (QDomDocument &doc, QDomElement &parentElem) const
 Write base class members to xml. More...
 
virtual int xBlockSize () const
 Gets block size. More...
 
virtual int xSize () const
 Gets raster size. More...
 
virtual int yBlockSize () const
 
virtual int ySize () const
 

Static Public Attributes

static const QRgb NODATA_COLOR = qRgba( 0, 0, 0, 0 )
 

Protected Member Functions

void _writeXml (QDomDocument &doc, QDomElement &rasterRendererElem) const
 Write upper class info into rasterrenderer element (called by writeXml method of subclasses) More...
 
QRgb renderColorForNodataPixel () const
 Returns the color for the renderer to use to represent nodata pixels. More...
 
- Protected Member Functions inherited from QgsRasterInterface
void initHistogram (QgsRasterHistogram &histogram, int bandNo, int binCount, double minimum=std::numeric_limits< double >::quiet_NaN(), double maximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &boundingBox=QgsRectangle(), int sampleSize=0, bool includeOutOfRange=false)
 Fill in histogram defaults if not specified. More...
 
Q_DECL_DEPRECATED void initStatistics (QgsRasterBandStats &statistics, int bandNo, int stats, const QgsRectangle &boundingBox=QgsRectangle(), int binCount=0) const
 Fill in statistics defaults if not specified. More...
 
void initStatistics (QgsRasterBandStats &statistics, int bandNo, Qgis::RasterBandStatistics stats=Qgis::RasterBandStatistic::All, const QgsRectangle &boundingBox=QgsRectangle(), int binCount=0) const
 Fill in statistics defaults if not specified. More...
 

Protected Attributes

int mAlphaBand = -1
 Read alpha value from band. More...
 
QgsRasterMinMaxOrigin mMinMaxOrigin
 Origin of min/max values. More...
 
double mOpacity = 1.0
 Global alpha value (0-1) More...
 
QgsRasterTransparencymRasterTransparency = nullptr
 Raster transparency per color or value. Overwrites global alpha value. More...
 
QString mType
 
- Protected Attributes inherited from QgsRasterInterface
QList< QgsRasterHistogrammHistograms
 List of cached histograms, all bands mixed. More...
 
QgsRasterInterfacemInput = nullptr
 
bool mOn = true
 
QList< QgsRasterBandStatsmStatistics
 List of cached statistics, all bands mixed. More...
 

Additional Inherited Members

- Public Types inherited from QgsRasterInterface
enum  Capability {
  NoCapabilities = 0 , Size = 1 << 1 , Create = 1 << 2 , Remove = 1 << 3 ,
  BuildPyramids = 1 << 4 , Identify = 1 << 5 , IdentifyValue = 1 << 6 , IdentifyText = 1 << 7 ,
  IdentifyHtml = 1 << 8 , IdentifyFeature = 1 << 9 , Prefetch = 1 << 10
}
 If you add to this, please also add to capabilitiesString() More...
 

Detailed Description

Raster renderer pipe that applies colors to a raster.

Definition at line 40 of file qgsrasterrenderer.h.

Constructor & Destructor Documentation

◆ QgsRasterRenderer() [1/2]

QgsRasterRenderer::QgsRasterRenderer ( QgsRasterInterface input = nullptr,
const QString &  type = QString() 
)

Constructor for QgsRasterRenderer.

Definition at line 33 of file qgsrasterrenderer.cpp.

◆ ~QgsRasterRenderer()

QgsRasterRenderer::~QgsRasterRenderer ( )
override

Definition at line 39 of file qgsrasterrenderer.cpp.

◆ QgsRasterRenderer() [2/2]

QgsRasterRenderer::QgsRasterRenderer ( const QgsRasterRenderer )
delete

QgsRasterRenderer cannot be copied. Use clone() instead.

Member Function Documentation

◆ _writeXml()

void QgsRasterRenderer::_writeXml ( QDomDocument &  doc,
QDomElement &  rasterRendererElem 
) const
protected

Write upper class info into rasterrenderer element (called by writeXml method of subclasses)

Definition at line 158 of file qgsrasterrenderer.cpp.

◆ accept()

bool QgsRasterRenderer::accept ( QgsStyleEntityVisitorInterface visitor) const
virtual

Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer.

Returns true if the visitor should continue visiting other objects, or false if visiting should be canceled.

Since
QGIS 3.10

Reimplemented in QgsSingleBandPseudoColorRenderer, and QgsPalettedRasterRenderer.

Definition at line 243 of file qgsrasterrenderer.cpp.

◆ alphaBand()

int QgsRasterRenderer::alphaBand ( ) const
inline

Definition at line 165 of file qgsrasterrenderer.h.

◆ bandCount()

int QgsRasterRenderer::bandCount ( ) const
overridevirtual

Gets number of bands.

Implements QgsRasterInterface.

Definition at line 44 of file qgsrasterrenderer.cpp.

◆ block()

QgsRasterBlock* QgsRasterRenderer::block ( int  bandNo,
const QgsRectangle extent,
int  width,
int  height,
QgsRasterBlockFeedback feedback = nullptr 
)
overridepure virtual

Read block of data using given extent and size.

Returns pointer to data. Caller is responsible to free the memory returned.

Parameters
bandNoband number
extentextent of block
widthpixel width of block
heightpixel height of block
feedbackoptional raster feedback object for cancellation/preview. Added in QGIS 3.0.

Implements QgsRasterInterface.

Implemented in QgsSingleBandPseudoColorRenderer, QgsSingleBandGrayRenderer, QgsSingleBandColorDataRenderer, QgsRasterContourRenderer, QgsPalettedRasterRenderer, QgsMultiBandColorRenderer, and QgsHillshadeRenderer.

◆ canCreateRasterAttributeTable()

bool QgsRasterRenderer::canCreateRasterAttributeTable ( ) const
virtual

Returns true if the renderer is suitable for attribute table creation.

The default implementation returns false.

Since
QGIS 3.30

Reimplemented in QgsSingleBandPseudoColorRenderer, and QgsPalettedRasterRenderer.

Definition at line 69 of file qgsrasterrenderer.cpp.

◆ clone()

QgsRasterRenderer* QgsRasterRenderer::clone ( ) const
overridepure virtual

◆ copyCommonProperties()

void QgsRasterRenderer::copyCommonProperties ( const QgsRasterRenderer other,
bool  copyMinMaxOrigin = true 
)

Copies common properties like opacity / transparency data from other renderer.

Useful when cloning renderers.

Definition at line 216 of file qgsrasterrenderer.cpp.

◆ createLegendNodes()

QList< QgsLayerTreeModelLegendNode * > QgsRasterRenderer::createLegendNodes ( QgsLayerTreeLayer nodeLayer)
virtual

Creates a set of legend nodes representing the renderer.

The default implementation calls legendSymbologyItems() and creates corresponding legend nodes for each returned symbology item.

Subclasses can override this to return more legend nodes which better represent the renderer.

Since
QGIS 3.18

Reimplemented in QgsSingleBandPseudoColorRenderer, QgsSingleBandGrayRenderer, QgsRasterContourRenderer, QgsPalettedRasterRenderer, and QgsMultiBandColorRenderer.

Definition at line 130 of file qgsrasterrenderer.cpp.

◆ dataType()

Qgis::DataType QgsRasterRenderer::dataType ( int  bandNo) const
overridevirtual

Returns data type for the band specified by number.

Implements QgsRasterInterface.

Definition at line 53 of file qgsrasterrenderer.cpp.

◆ flags()

Qgis::RasterRendererFlags QgsRasterRenderer::flags ( ) const
virtual

Returns flags which dictate renderer behavior.

Since
QGIS 3.28

Reimplemented in QgsSingleBandPseudoColorRenderer, QgsSingleBandGrayRenderer, QgsSingleBandColorDataRenderer, QgsPalettedRasterRenderer, QgsMultiBandColorRenderer, and QgsHillshadeRenderer.

Definition at line 64 of file qgsrasterrenderer.cpp.

◆ inputBand()

int QgsRasterRenderer::inputBand ( ) const
virtual

Returns the input band for the renderer, or -1 if no input band is available.

For renderers which utilize multiple input bands -1 will be returned. In these cases usesBands() will return a list of all utilized bands (including alpha bands).

See also
setInputBand()
usesBands()
Since
QGIS 3.38

Reimplemented in QgsSingleBandPseudoColorRenderer, QgsSingleBandGrayRenderer, QgsSingleBandColorDataRenderer, QgsRasterContourRenderer, QgsPalettedRasterRenderer, and QgsHillshadeRenderer.

Definition at line 100 of file qgsrasterrenderer.cpp.

◆ legendSymbologyItems()

QList< QPair< QString, QColor > > QgsRasterRenderer::legendSymbologyItems ( ) const
virtual

Returns symbology items if provided by renderer.

See also
createLegendNodes()

Reimplemented in QgsSingleBandPseudoColorRenderer, QgsSingleBandGrayRenderer, and QgsPalettedRasterRenderer.

Definition at line 125 of file qgsrasterrenderer.cpp.

◆ minMaxOrigin()

const QgsRasterMinMaxOrigin& QgsRasterRenderer::minMaxOrigin ( ) const
inline

Returns const reference to origin of min/max values.

Definition at line 203 of file qgsrasterrenderer.h.

◆ nodataColor()

QColor QgsRasterRenderer::nodataColor ( ) const
inline

Returns the color to use for shading nodata pixels.

If the returned value is an invalid color then the default transparent rendering of nodata values will be used.

See also
renderColorForNodataPixel()
setNodataColor()
Since
QGIS 3.12

Definition at line 148 of file qgsrasterrenderer.h.

◆ opacity()

double QgsRasterRenderer::opacity ( ) const
inline

Returns the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque).

See also
setOpacity()

Definition at line 136 of file qgsrasterrenderer.h.

◆ operator=()

const QgsRasterRenderer& QgsRasterRenderer::operator= ( const QgsRasterRenderer )
delete

QgsRasterRenderer cannot be copied. Use clone() instead.

◆ rasterTransparency()

const QgsRasterTransparency* QgsRasterRenderer::rasterTransparency ( ) const
inline

Definition at line 162 of file qgsrasterrenderer.h.

◆ readXml()

void QgsRasterRenderer::readXml ( const QDomElement &  rendererElem)
overridevirtual

Sets base class members from xml. Usually called from create() methods of subclasses.

Reimplemented from QgsRasterInterface.

Definition at line 188 of file qgsrasterrenderer.cpp.

◆ renderColorForNodataPixel()

QRgb QgsRasterRenderer::renderColorForNodataPixel ( ) const
protected

Returns the color for the renderer to use to represent nodata pixels.

Subclasses should use this rather then nodataColor() to determine the color to use for nodata pixels during an actual rendering operation.

Since
QGIS 3.10

Definition at line 180 of file qgsrasterrenderer.cpp.

◆ setAlphaBand()

void QgsRasterRenderer::setAlphaBand ( int  band)
inline

Definition at line 164 of file qgsrasterrenderer.h.

◆ setInput()

bool QgsRasterRenderer::setInput ( QgsRasterInterface input)
overridevirtual

Set input.

Returns true if set correctly, false if cannot use that input

Reimplemented from QgsRasterInterface.

Reimplemented in QgsSingleBandColorDataRenderer.

Definition at line 74 of file qgsrasterrenderer.cpp.

◆ setInputBand()

bool QgsRasterRenderer::setInputBand ( int  band)
virtual

Attempts to set the input band for the renderer.

Returns true if the band was successfully set, or false if the band could not be set.

Note
Not all renderers support setting the input band.
See also
inputBand()
usesBands()
Since
QGIS 3.38

Reimplemented in QgsSingleBandPseudoColorRenderer, QgsSingleBandGrayRenderer, QgsSingleBandColorDataRenderer, QgsRasterContourRenderer, QgsPalettedRasterRenderer, and QgsHillshadeRenderer.

Definition at line 105 of file qgsrasterrenderer.cpp.

◆ setMinMaxOrigin()

void QgsRasterRenderer::setMinMaxOrigin ( const QgsRasterMinMaxOrigin origin)
inline

Sets origin of min/max values.

Definition at line 206 of file qgsrasterrenderer.h.

◆ setNodataColor()

void QgsRasterRenderer::setNodataColor ( const QColor &  color)
inline

Sets the color to use for shading nodata pixels.

If color is an invalid color then the default transparent rendering of nodata values will be used.

See also
nodataColor()
Since
QGIS 3.12

Definition at line 159 of file qgsrasterrenderer.h.

◆ setOpacity()

void QgsRasterRenderer::setOpacity ( double  opacity)
inline

Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque).

See also
opacity()

Definition at line 129 of file qgsrasterrenderer.h.

◆ setRasterTransparency()

void QgsRasterRenderer::setRasterTransparency ( QgsRasterTransparency t)

Definition at line 119 of file qgsrasterrenderer.cpp.

◆ toSld()

void QgsRasterRenderer::toSld ( QDomDocument &  doc,
QDomElement &  element,
const QVariantMap &  props = QVariantMap() 
) const
virtual

Used from subclasses to create SLD Rule elements following SLD v1.0 specs.

Since
QGIS 3.6

Reimplemented in QgsSingleBandPseudoColorRenderer, QgsSingleBandGrayRenderer, QgsPalettedRasterRenderer, QgsMultiBandColorRenderer, and QgsHillshadeRenderer.

Definition at line 229 of file qgsrasterrenderer.cpp.

◆ type()

virtual QString QgsRasterRenderer::type ( ) const
inlinevirtual

Returns a unique string representation of the renderer type.

Definition at line 69 of file qgsrasterrenderer.h.

◆ usesBands()

virtual QList<int> QgsRasterRenderer::usesBands ( ) const
inlinevirtual

◆ usesTransparency()

bool QgsRasterRenderer::usesTransparency ( ) const

Definition at line 110 of file qgsrasterrenderer.cpp.

Member Data Documentation

◆ mAlphaBand

int QgsRasterRenderer::mAlphaBand = -1
protected

Read alpha value from band.

Is combined with value from raster transparency / global alpha value. Default: -1 (not set)

Definition at line 241 of file qgsrasterrenderer.h.

◆ mMinMaxOrigin

QgsRasterMinMaxOrigin QgsRasterRenderer::mMinMaxOrigin
protected

Origin of min/max values.

Definition at line 244 of file qgsrasterrenderer.h.

◆ mOpacity

double QgsRasterRenderer::mOpacity = 1.0
protected

Global alpha value (0-1)

Definition at line 233 of file qgsrasterrenderer.h.

◆ mRasterTransparency

QgsRasterTransparency* QgsRasterRenderer::mRasterTransparency = nullptr
protected

Raster transparency per color or value. Overwrites global alpha value.

Definition at line 235 of file qgsrasterrenderer.h.

◆ mType

QString QgsRasterRenderer::mType
protected

Definition at line 230 of file qgsrasterrenderer.h.

◆ NODATA_COLOR

const QRgb QgsRasterRenderer::NODATA_COLOR = qRgba( 0, 0, 0, 0 )
static

Definition at line 47 of file qgsrasterrenderer.h.


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