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;
56 const int inputBand = elem.attribute( QStringLiteral(
"band" ), QStringLiteral(
"-1" ) ).toInt();
57 const double contourInterval = elem.attribute( QStringLiteral(
"contour-interval" ), QStringLiteral(
"100" ) ).toDouble();
58 const double contourIndexInterval = elem.attribute( QStringLiteral(
"contour-index-interval" ), QStringLiteral(
"0" ) ).toDouble();
59 const double downscale = elem.attribute( QStringLiteral(
"downscale" ), QStringLiteral(
"4" ) ).toDouble();
66 QDomElement symbolsElem = elem.firstChildElement( QStringLiteral(
"symbols" ) );
67 if ( !symbolsElem.isNull() )
70 if ( symbolMap.contains( QStringLiteral(
"contour" ) ) )
72 QgsSymbol *symbol = symbolMap.take( QStringLiteral(
"contour" ) );
76 if ( symbolMap.contains( QStringLiteral(
"index-contour" ) ) )
78 QgsSymbol *symbol = symbolMap.take( QStringLiteral(
"index-contour" ) );
88 if ( parentElem.isNull() )
93 QDomElement rasterRendererElem = doc.createElement( QStringLiteral(
"rasterrenderer" ) );
96 rasterRendererElem.setAttribute( QStringLiteral(
"band" ), mInputBand );
97 rasterRendererElem.setAttribute( QStringLiteral(
"contour-interval" ), mContourInterval );
98 rasterRendererElem.setAttribute( QStringLiteral(
"contour-index-interval" ), mContourIndexInterval );
99 rasterRendererElem.setAttribute( QStringLiteral(
"downscale" ), mDownscale );
102 symbols[QStringLiteral(
"contour" )] = mContourSymbol.get();
103 if ( mContourIndexSymbol )
104 symbols[QStringLiteral(
"index-contour" )] = mContourIndexSymbol.get();
106 rasterRendererElem.appendChild( symbolsElem );
108 parentElem.appendChild( rasterRendererElem );
125 QPolygonF polygon( nPoints );
126 QPointF *d = polygon.data();
127 for (
int i = 0; i < nPoints; ++i )
129 d[i] = QPointF( padfX[i] * crData->
scaleX, padfY[i] * crData->
scaleY );
143 std::unique_ptr< QgsRasterBlock > outputBlock(
new QgsRasterBlock() );
144 if ( !
mInput || !mContourSymbol )
146 return outputBlock.release();
149 const int inputWidth =
static_cast<int>( round( width / mDownscale ) );
150 const int inputHeight =
static_cast<int>( round( height / mDownscale ) );
152 std::unique_ptr< QgsRasterBlock > inputBlock(
mInput->
block( mInputBand,
extent, inputWidth, inputHeight, feedback ) );
153 if ( !inputBlock || inputBlock->isEmpty() )
155 QgsDebugMsg( QStringLiteral(
"No raster data!" ) );
156 return outputBlock.release();
160 return outputBlock.release();
161 double *scanline =
reinterpret_cast<double *
>( inputBlock->bits() );
163 QImage img( width, height, QImage::Format_ARGB32_Premultiplied );
164 img.fill( Qt::transparent );
167 p.setRenderHint( QPainter::Antialiasing );
173 crData.
scaleX = width / double( inputWidth );
174 crData.
scaleY = height / double( inputHeight );
175 crData.
symbol = mContourSymbol.get();
184 const double contourBase = 0.;
185 GDALContourGeneratorH cg = GDAL_CG_Create( inputBlock->width(), inputBlock->height(),
186 inputBlock->hasNoDataValue(), inputBlock->noDataValue(),
187 mContourInterval, contourBase,
189 for (
int i = 0; i < inputHeight; ++i )
194 GDAL_CG_FeedLine( cg, scanline );
195 scanline += inputWidth;
197 GDAL_CG_Destroy( cg );
205 outputBlock->setImage( &img );
206 return outputBlock.release();
212 if ( mInputBand != -1 )
214 bandList << mInputBand;
221 QList<QgsLayerTreeModelLegendNode *> nodes;
223 const QgsLegendSymbolItem contourItem( mContourSymbol.get(), QString::number( mContourInterval ), QStringLiteral(
"contour" ) );
226 if ( mContourIndexInterval > 0 )
228 const QgsLegendSymbolItem indexItem( mContourIndexSymbol.get(), QString::number( mContourIndexInterval ), QStringLiteral(
"index" ) );
237 mContourSymbol.reset( symbol );
242 mContourIndexSymbol.reset( symbol );
@ Float64
Sixty four bit floating point (double)
bool isCanceled() const SIP_HOLDGIL
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.
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.
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...
void setInputBand(int band)
Sets the number of the input raster band.
int inputBand() const
Returns the number of the input raster band.
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)
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)
CPLErr _rasterContourWriter(double dfLevel, int nPoints, double *padfX, double *padfY, void *ptr)
QMap< QString, QgsSymbol * > QgsSymbolMap
QgsRenderContext * context
QgsLineSymbol * indexSymbol