27#include <QCoreApplication>
28#include <QDomDocument>
80 if ( !
input )
return false;
89 for (
int i = 1; i <=
input->bandCount(); i++ )
130 return QList< QPair< QString, QColor > >();
135 QList<QgsLayerTreeModelLegendNode *> nodes;
138 if ( rasterItemList.isEmpty() )
144 const int max_count = 1000;
146 for (
auto itemIt = rasterItemList.constBegin(); itemIt != rasterItemList.constEnd(); ++itemIt, ++count )
150 if ( count == max_count )
152 const QString label = tr(
"following %n item(s) not displayed",
nullptr, rasterItemList.size() - max_count );
163 if ( rasterRendererElem.isNull() )
168 rasterRendererElem.setAttribute( QStringLiteral(
"type" ),
mType );
169 rasterRendererElem.setAttribute( QStringLiteral(
"opacity" ), QString::number(
mOpacity ) );
170 rasterRendererElem.setAttribute( QStringLiteral(
"alphaBand" ),
mAlphaBand );
171 rasterRendererElem.setAttribute( QStringLiteral(
"nodataColor" ), mNodataColor.isValid() ?
QgsColorUtils::colorToString( mNodataColor ) : QString() );
178 QDomElement minMaxOriginElem = doc.createElement( QStringLiteral(
"minMaxOrigin" ) );
180 rasterRendererElem.appendChild( minMaxOriginElem );
185 if ( !mNodataColor.isValid() )
188 return mNodataColor.rgba();
193 if ( rendererElem.isNull() )
198 mType = rendererElem.attribute( QStringLiteral(
"type" ) );
199 mOpacity = rendererElem.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1.0" ) ).toDouble();
200 mAlphaBand = rendererElem.attribute( QStringLiteral(
"alphaBand" ), QStringLiteral(
"-1" ) ).toInt();
201 const QString colorEncoded = rendererElem.attribute( QStringLiteral(
"nodataColor" ) );
204 const QDomElement rasterTransparencyElem = rendererElem.firstChildElement( QStringLiteral(
"rasterTransparency" ) );
205 if ( !rasterTransparencyElem.isNull() )
212 const QDomElement minMaxOriginElem = rendererElem.firstChildElement( QStringLiteral(
"minMaxOrigin" ) );
213 if ( !minMaxOriginElem.isNull() )
228 if ( copyMinMaxOrigin )
236 toSld( doc, element, context );
241 QDomElement rasterSymbolizerElem = doc.createElement( QStringLiteral(
"sld:RasterSymbolizer" ) );
242 element.appendChild( rasterSymbolizerElem );
247 QDomElement opacityElem = doc.createElement( QStringLiteral(
"sld:Opacity" ) );
248 opacityElem.appendChild( doc.createTextNode( QString::number(
opacity() ) ) );
249 rasterSymbolizerElem.appendChild( opacityElem );
QFlags< RasterRendererFlag > RasterRendererFlags
Flags which control behavior of raster renderers.
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.
@ UpdatedCanvas
Constantly updated extent of the canvas is used to compute statistics.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
Layer tree node points to a map layer.
static bool typeIsNumeric(Qgis::DataType type)
Returns true if a data type is numeric.
QgsRasterInterface(QgsRasterInterface *input=nullptr)
QgsRasterInterface * mInput
virtual QgsRectangle extent() const
Gets the extent of the interface.
virtual QgsRasterInterface * input() const
Current input.
QColor nodataColor() const
Returns the color to use for shading nodata pixels.
QgsRasterRenderer(QgsRasterInterface *input=nullptr, const QString &type=QString())
Constructor for QgsRasterRenderer.
virtual QString type() const
Returns a unique string representation of the renderer type.
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
virtual int inputBand() const
Returns the input band for the renderer, or -1 if no input band is available.
int mAlphaBand
Read alpha value from band.
QgsRectangle mLastRectangleUsedByRefreshContrastEnhancementIfNeeded
To save computations and possible infinite cycle of notifications.
virtual bool setInputBand(int band)
Attempts to set the input band for the renderer.
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.
std::unique_ptr< QgsRasterTransparency > mRasterTransparency
Raster transparency per color or value. Overwrites global alpha value.
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.
virtual bool refresh(const QgsRectangle &extent, const QList< double > &min, const QList< double > &max, bool forceRefresh=false)
Refreshes the renderer according to the min and max values associated with the extent.
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.
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
bool needsRefresh(const QgsRectangle &extent) const
Checks if the renderer needs to be refreshed according to extent.
virtual Q_DECL_DEPRECATED 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...
A rectangle specified with double values.
Implementation of legend node interface for displaying arbitrary labels with icons.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
void setExtraProperties(const QVariantMap &properties)
Sets the open ended set of properties that can drive/inform the SLD encoding.
An interface for classes which can visit style entity (e.g.
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)