37 renderer->mContourSymbol.reset( mContourSymbol ? mContourSymbol->clone() : nullptr );
38 renderer->mContourIndexSymbol.reset( mContourIndexSymbol ? mContourIndexSymbol->clone() : nullptr );
39 renderer->mContourInterval = mContourInterval;
40 renderer->mContourIndexInterval = mContourIndexInterval;
41 renderer->mInputBand = mInputBand;
42 renderer->mDownscale = mDownscale;
61 const int inputBand = elem.attribute( QStringLiteral(
"band" ), QStringLiteral(
"-1" ) ).toInt();
62 const double contourInterval = elem.attribute( QStringLiteral(
"contour-interval" ), QStringLiteral(
"100" ) ).toDouble();
63 const double contourIndexInterval = elem.attribute( QStringLiteral(
"contour-index-interval" ), QStringLiteral(
"0" ) ).toDouble();
64 const double downscale = elem.attribute( QStringLiteral(
"downscale" ), QStringLiteral(
"4" ) ).toDouble();
71 QDomElement symbolsElem = elem.firstChildElement( QStringLiteral(
"symbols" ) );
72 if ( !symbolsElem.isNull() )
75 if ( symbolMap.contains( QStringLiteral(
"contour" ) ) )
77 QgsSymbol *symbol = symbolMap.take( QStringLiteral(
"contour" ) );
81 if ( symbolMap.contains( QStringLiteral(
"index-contour" ) ) )
83 QgsSymbol *symbol = symbolMap.take( QStringLiteral(
"index-contour" ) );
93 if ( parentElem.isNull() )
98 QDomElement rasterRendererElem = doc.createElement( QStringLiteral(
"rasterrenderer" ) );
101 rasterRendererElem.setAttribute( QStringLiteral(
"band" ), mInputBand );
102 rasterRendererElem.setAttribute( QStringLiteral(
"contour-interval" ), mContourInterval );
103 rasterRendererElem.setAttribute( QStringLiteral(
"contour-index-interval" ), mContourIndexInterval );
104 rasterRendererElem.setAttribute( QStringLiteral(
"downscale" ), mDownscale );
107 symbols[QStringLiteral(
"contour" )] = mContourSymbol.get();
108 if ( mContourIndexSymbol )
109 symbols[QStringLiteral(
"index-contour" )] = mContourIndexSymbol.get();
111 rasterRendererElem.appendChild( symbolsElem );
113 parentElem.appendChild( rasterRendererElem );
130 QPolygonF polygon( nPoints );
131 QPointF *d = polygon.data();
132 for (
int i = 0; i < nPoints; ++i )
134 d[i] = QPointF( padfX[i] * crData->
scaleX, padfY[i] * crData->
scaleY );
148 std::unique_ptr< QgsRasterBlock > outputBlock(
new QgsRasterBlock() );
149 if ( !
mInput || !mContourSymbol )
151 return outputBlock.release();
154 const int inputWidth =
static_cast<int>( round( width / mDownscale ) );
155 const int inputHeight =
static_cast<int>( round( height / mDownscale ) );
157 std::unique_ptr< QgsRasterBlock > inputBlock(
mInput->
block( mInputBand,
extent, inputWidth, inputHeight, feedback ) );
158 if ( !inputBlock || inputBlock->isEmpty() )
161 return outputBlock.release();
165 return outputBlock.release();
166 double *scanline =
reinterpret_cast<double *
>( inputBlock->bits() );
168 QImage img( width, height, QImage::Format_ARGB32_Premultiplied );
169 img.fill( Qt::transparent );
172 p.setRenderHint( QPainter::Antialiasing );
178 crData.
scaleX = width / double( inputWidth );
179 crData.
scaleY = height / double( inputHeight );
180 crData.
symbol = mContourSymbol.get();
189 const double contourBase = 0.;
190 GDALContourGeneratorH cg = GDAL_CG_Create( inputBlock->width(), inputBlock->height(),
191 inputBlock->hasNoDataValue(), inputBlock->noDataValue(),
192 mContourInterval, contourBase,
194 for (
int i = 0; i < inputHeight; ++i )
199 GDAL_CG_FeedLine( cg, scanline );
200 scanline += inputWidth;
202 GDAL_CG_Destroy( cg );
210 outputBlock->setImage( &img );
211 return outputBlock.release();
217 if ( mInputBand != -1 )
219 bandList << mInputBand;
226 QList<QgsLayerTreeModelLegendNode *> nodes;
228 const QgsLegendSymbolItem contourItem( mContourSymbol.get(), QString::number( mContourInterval ), QStringLiteral(
"contour" ) );
231 if ( mContourIndexInterval > 0 )
233 const QgsLegendSymbolItem indexItem( mContourIndexSymbol.get(), QString::number( mContourIndexInterval ), QStringLiteral(
"index" ) );
252 else if ( band > 0 && band <= mInput->
bandCount() )
262 mContourSymbol.reset( symbol );
267 mContourIndexSymbol.reset( symbol );
QFlags< RasterRendererFlag > RasterRendererFlags
Flags which control behavior of raster renderers.
@ UseNoDataForOutOfRangePixels
Out of range pixels (eg those values outside of the rendered map's z range filter) should be set usin...
@ Float64
Sixty four bit floating point (double)
bool isCanceled() const
Tells whether the operation has been canceled already.
Layer tree node points to a map layer.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
A line symbol type, for rendering LineString and MultiLineString geometries.
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol along the line joining points, using the given render context.
Feedback object tailored for raster block reading.
Raster renderer that generates contours on the fly for a source raster band.
int inputBand() const override
Returns the input band for the renderer, or -1 if no input band is available.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
Creates an instance of the renderer based on definition from XML (used by renderer registry)
QgsRasterContourRenderer * clone() const override
Clone itself, create deep copy.
void setDownscale(double scale)
Sets by how much the renderer will scale down the request to the data provider.
QgsRasterContourRenderer(QgsRasterInterface *input)
Creates a contour renderer.
void setContourIndexSymbol(QgsLineSymbol *symbol)
Sets the symbol of index contour lines.
void setContourInterval(double interval)
Sets the interval of contour lines generation.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
Qgis::RasterRendererFlags flags() const override
Returns flags which dictate renderer behavior.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Creates a set of legend nodes representing the renderer.
~QgsRasterContourRenderer() override
double downscale() const
Returns by how much the renderer will scale down the request to the data provider.
void setContourIndexInterval(double interval)
Sets the interval of index contour lines (index contour lines are typical further apart and with a wi...
bool setInputBand(int band) override
Attempts to set the input band for the renderer.
double contourInterval() const
Returns the interval of contour lines generation.
double contourIndexInterval() const
Returns the interval of index contour lines (index contour lines are typical further apart and with a...
void setContourSymbol(QgsLineSymbol *symbol)
Sets the symbol used for contour lines. Takes ownership of the passed symbol.
QList< int > usesBands() const override
Returns a list of band numbers used by the renderer.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)=0
Read block of data using given extent and size.
QgsRasterInterface * mInput
virtual QgsRectangle extent() const
Gets the extent of the interface.
virtual QgsRasterInterface * input() const
Current input.
Raster renderer pipe that applies colors to a raster.
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.
void copyCommonProperties(const QgsRasterRenderer *other, bool copyMinMaxOrigin=true)
Copies common properties like opacity / transparency data from other renderer.
void readXml(const QDomElement &rendererElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
static QgsSymbolMap loadSymbols(QDomElement &element, const QgsReadWriteContext &context)
Reads a collection of symbols from XML and returns them in a map. Caller is responsible for deleting ...
static QDomElement saveSymbols(QgsSymbolMap &symbols, const QString &tagName, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a collection of symbols to XML with specified tagName for the top-level element.
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
Abstract base class for all rendered symbols.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
Qgis::SymbolType type() const
Returns the symbol's type.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
static QgsSymbol * defaultSymbol(Qgis::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
#define QgsDebugError(str)
CPLErr _rasterContourWriter(double dfLevel, int nPoints, double *padfX, double *padfY, void *ptr)
QMap< QString, QgsSymbol * > QgsSymbolMap
QgsRenderContext * context
QgsLineSymbol * indexSymbol