24#include <QCoreApplication>
25#include <QDomDocument>
66 return Qgis::RasterRendererFlags();
77 if ( !
input )
return false;
117 return QList< QPair< QString, QColor > >();
122 QList<QgsLayerTreeModelLegendNode *> nodes;
125 if ( rasterItemList.isEmpty() )
131 const int max_count = 1000;
133 for (
auto itemIt = rasterItemList.constBegin(); itemIt != rasterItemList.constEnd(); ++itemIt, ++count )
137 if ( count == max_count )
139 const QString label = tr(
"following %1 items\nnot displayed" ).arg( rasterItemList.size() - max_count );
150 if ( rasterRendererElem.isNull() )
155 rasterRendererElem.setAttribute( QStringLiteral(
"type" ),
mType );
156 rasterRendererElem.setAttribute( QStringLiteral(
"opacity" ), QString::number(
mOpacity ) );
157 rasterRendererElem.setAttribute( QStringLiteral(
"alphaBand" ),
mAlphaBand );
165 QDomElement minMaxOriginElem = doc.createElement( QStringLiteral(
"minMaxOrigin" ) );
167 rasterRendererElem.appendChild( minMaxOriginElem );
172 if ( !mNodataColor.isValid() )
175 return mNodataColor.rgba();
180 if ( rendererElem.isNull() )
185 mType = rendererElem.attribute( QStringLiteral(
"type" ) );
186 mOpacity = rendererElem.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1.0" ) ).toDouble();
187 mAlphaBand = rendererElem.attribute( QStringLiteral(
"alphaBand" ), QStringLiteral(
"-1" ) ).toInt();
188 const QString colorEncoded = rendererElem.attribute( QStringLiteral(
"nodataColor" ) );
191 const QDomElement rasterTransparencyElem = rendererElem.firstChildElement( QStringLiteral(
"rasterTransparency" ) );
192 if ( !rasterTransparencyElem.isNull() )
199 const QDomElement minMaxOriginElem = rendererElem.firstChildElement( QStringLiteral(
"minMaxOrigin" ) );
200 if ( !minMaxOriginElem.isNull() )
215 if ( copyMinMaxOrigin )
221 QDomElement rasterSymbolizerElem = doc.createElement( QStringLiteral(
"sld:RasterSymbolizer" ) );
222 element.appendChild( rasterSymbolizerElem );
227 QDomElement opacityElem = doc.createElement( QStringLiteral(
"sld:Opacity" ) );
228 opacityElem.appendChild( doc.createTextNode( QString::number(
opacity() ) ) );
229 rasterSymbolizerElem.appendChild( opacityElem );
DataType
Raster data types.
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
@ UnknownDataType
Unknown or unspecified type.
Layer tree node points to a map layer.
static bool typeIsNumeric(Qgis::DataType type)
Returns true if data type is numeric.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
virtual int bandCount() const =0
Gets number of bands.
QgsRasterInterface * mInput
virtual QgsRasterInterface * input() const
Current input.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Serialize object.
void readXml(const QDomElement &elem)
Deserialize object.
Raster renderer pipe that applies colors to a raster.
QColor nodataColor() const
Returns the color to use for shading nodata pixels.
QgsRasterRenderer(QgsRasterInterface *input=nullptr, const QString &type=QString())
Constructor for QgsRasterRenderer.
virtual bool canCreateRasterAttributeTable() const
Returns true if the renderer is suitable for attribute table creation.
double mOpacity
Global alpha value (0-1)
bool setInput(QgsRasterInterface *input) override
Set input.
void setMinMaxOrigin(const QgsRasterMinMaxOrigin &origin)
Sets origin of min/max values.
~QgsRasterRenderer() override
int mAlphaBand
Read alpha value from band.
QRgb renderColorForNodataPixel() const
Returns the color for the renderer to use to represent nodata pixels.
const QgsRasterTransparency * rasterTransparency() const
virtual Qgis::RasterRendererFlags flags() const
Returns flags which dictate renderer behavior.
const QgsRasterMinMaxOrigin & minMaxOrigin() const
Returns const reference to origin of min/max values.
void _writeXml(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXml method of subclasses)
int bandCount() const override
Gets number of bands.
double opacity() const
Returns the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
void setAlphaBand(int band)
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
QgsRasterMinMaxOrigin mMinMaxOrigin
Origin of min/max values.
QgsRasterTransparency * mRasterTransparency
Raster transparency per color or value. Overwrites global alpha value.
virtual QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer)
Creates a set of legend nodes representing the renderer.
void setRasterTransparency(QgsRasterTransparency *t)
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
bool usesTransparency() const
void copyCommonProperties(const QgsRasterRenderer *other, bool copyMinMaxOrigin=true)
Copies common properties like opacity / transparency data from other renderer.
static const QRgb NODATA_COLOR
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.
void setNodataColor(const QColor &color)
Sets the color to use for shading nodata pixels.
virtual QList< QPair< QString, QColor > > legendSymbologyItems() const
Returns symbology items if provided by renderer.
void readXml(const QDomElement &rendererElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
Qgis::DataType dataType(int bandNo) const override
Returns data type for the band specified by number.
Implementation of legend node interface for displaying raster legend entries.
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Writes the transparency information to an XML document.
bool isEmpty() const
True if there are no entries in the pixel lists except the nodata value.
void readXml(const QDomElement &elem)
Reads the transparency information from an XML document.
Implementation of legend node interface for displaying arbitrary label with icon.
An interface for classes which can visit style entity (e.g.
static QColor decodeColor(const QString &str)
static QString encodeColor(const QColor &color)
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
#define QgsDebugMsgLevel(str, level)