22 #include <QDomDocument> 23 #include <QDomElement> 30 , mClassificationMin( std::numeric_limits<double>::quiet_NaN() )
31 , mClassificationMax( std::numeric_limits<double>::quiet_NaN() )
52 if ( origColorRampShader )
84 int band = elem.attribute(
"band",
"-1" ).toInt();
86 QDomElement rasterShaderElem = elem.firstChildElement(
"rastershader" );
87 if ( !rasterShaderElem.isNull() )
90 shader->
readXML( rasterShaderElem );
109 if ( !
mInput || !mShader )
116 if ( !inputBlock || inputBlock->
isEmpty() )
130 if ( !alphaBlock || alphaBlock->
isEmpty() )
139 alphaBlock = inputBlock;
155 outputBlock->
setColor( i, myDefaultColor );
158 double val = inputBlock->
value( i );
159 int red, green, blue, alpha;
160 if ( !mShader->
shade( val, &red, &green, &blue, &alpha ) )
162 outputBlock->
setColor( i, myDefaultColor );
169 red *= ( alpha / 255.0 );
170 blue *= ( alpha / 255.0 );
171 green *= ( alpha / 255.0 );
174 if ( !hasTransparency )
176 outputBlock->
setColor( i, qRgba( red, green, blue, alpha ) );
188 currentOpacity *= alphaBlock->
value( i ) / 255.0;
191 outputBlock->
setColor( i, qRgba( currentOpacity * red, currentOpacity * green, currentOpacity * blue, currentOpacity * alpha ) );
206 if ( parentElem.isNull() )
211 QDomElement rasterRendererElem = doc.createElement(
"rasterrenderer" );
213 rasterRendererElem.setAttribute(
"band", mBand );
216 mShader->
writeXML( doc, rasterRendererElem );
218 rasterRendererElem.setAttribute(
"classificationMin", QString::number( mClassificationMin ) );
219 rasterRendererElem.setAttribute(
"classificationMax", QString::number( mClassificationMax ) );
222 parentElem.appendChild( rasterRendererElem );
230 if ( shaderFunction )
A rectangle specified with double values.
Interface for all raster shaders.
void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const override
Get symbology items if provided by renderer.
static int minMaxOriginFromName(QString theName)
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
void setClassificationMinMaxOrigin(int origin)
virtual QgsRasterInterface * input() const
Current input.
QgsRasterInterface * clone() const override
Clone itself, create deep copy.
void setColorRampItemList(const QList< QgsColorRampShader::ColorRampItem > &theList)
Set custom colormap.
QgsRasterShader * shader()
void setClassificationMax(double max)
bool isNoData(int row, int column)
Check if value at position is no data.
void setShader(QgsRasterShader *shader)
Takes ownership of the shader.
void readXML(const QDomElement &rendererElem) override
Sets base class members from xml.
void writeXML(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
bool usesTransparency() const
QgsRasterTransparency * mRasterTransparency
Raster transparency per color or value.
void writeXML(QDomDocument &doc, QDomElement &parent) const
bool setColor(int row, int column, QRgb color)
Set color on position.
static const QRgb NODATA_COLOR
int alphaValue(double, int theGlobalTransparency=255) const
Returns the transparency value for a single value Pixel.
QgsSingleBandPseudoColorRenderer(QgsRasterInterface *input, int band, QgsRasterShader *shader)
Note: takes ownership of QgsRasterShader.
double value(int row, int column) const
Read a single value if type of block is numeric.
int band() const
Returns the band used by the renderer.
QgsRasterShaderFunction * rasterShaderFunction()
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height) override
Read block of data using given extent and size.
The raster shade function applies a shader to a pixel at render time - typically used to render grays...
double maximumValue()
Return the maximum value for the raster shader.
Raster renderer pipe for single band pseudocolor.
bool shade(double, int *, int *, int *, int *)
generates and new RGBA value based on one input value
int mAlphaBand
Read alpha value from band.
void setAlphaBand(int band)
QList< int > usesBands() const override
Returns a list of band numbers used by the renderer.
void setRasterShaderFunction(QgsRasterShaderFunction *)
A public method that allows the user to set their own shader function.
Base class for processing filters like renderers, reprojector, resampler etc.
void setColorRampType(QgsColorRampShader::ColorRamp_TYPE theColorRampType)
Set the color ramp type.
unsigned long long qgssize
qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
bool reset(QGis::DataType theDataType, int theWidth, int theHeight)
Reset block.
~QgsSingleBandPseudoColorRenderer()
virtual void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const
virtual QgsRectangle extent()
Get the extent of the interface.
void setClassificationMin(double min)
static QString minMaxOriginName(int theOrigin)
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
double minimumValue()
Return the minimum value for the raster shader.
double mOpacity
Global alpha value (0-1)
void readXML(const QDomElement &elem)
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
void setOpacity(double opacity)
void _writeXML(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXML method of subclasses) ...
QgsRasterInterface * mInput
void setRasterTransparency(QgsRasterTransparency *t)
Raster renderer pipe that applies colors to a raster.
bool isEmpty() const
Returns true if block is empty, i.e.