QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
36 renderer->mContourSymbol.reset( mContourSymbol ? mContourSymbol->clone() :
nullptr );
37 renderer->mContourIndexSymbol.reset( mContourIndexSymbol ? mContourIndexSymbol->clone() :
nullptr );
38 renderer->mContourInterval = mContourInterval;
39 renderer->mContourIndexInterval = mContourIndexInterval;
40 renderer->mInputBand = mInputBand;
41 renderer->mDownscale = mDownscale;
55 int inputBand = elem.attribute( QStringLiteral(
"band" ), QStringLiteral(
"-1" ) ).toInt();
56 double contourInterval = elem.attribute( QStringLiteral(
"contour-interval" ), QStringLiteral(
"100" ) ).toDouble();
57 double contourIndexInterval = elem.attribute( QStringLiteral(
"contour-index-interval" ), QStringLiteral(
"0" ) ).toDouble();
58 double downscale = elem.attribute( QStringLiteral(
"downscale" ), QStringLiteral(
"4" ) ).toDouble();
65 QDomElement symbolsElem = elem.firstChildElement( QStringLiteral(
"symbols" ) );
66 if ( !symbolsElem.isNull() )
69 if ( symbolMap.contains( QStringLiteral(
"contour" ) ) )
71 QgsSymbol *symbol = symbolMap.take( QStringLiteral(
"contour" ) );
75 if ( symbolMap.contains( QStringLiteral(
"index-contour" ) ) )
77 QgsSymbol *symbol = symbolMap.take( QStringLiteral(
"index-contour" ) );
87 if ( parentElem.isNull() )
92 QDomElement rasterRendererElem = doc.createElement( QStringLiteral(
"rasterrenderer" ) );
95 rasterRendererElem.setAttribute( QStringLiteral(
"band" ), mInputBand );
96 rasterRendererElem.setAttribute( QStringLiteral(
"contour-interval" ), mContourInterval );
97 rasterRendererElem.setAttribute( QStringLiteral(
"contour-index-interval" ), mContourIndexInterval );
98 rasterRendererElem.setAttribute( QStringLiteral(
"downscale" ), mDownscale );
101 symbols[QStringLiteral(
"contour" )] = mContourSymbol.get();
102 if ( mContourIndexSymbol )
103 symbols[QStringLiteral(
"index-contour" )] = mContourIndexSymbol.get();
105 rasterRendererElem.appendChild( symbolsElem );
107 parentElem.appendChild( rasterRendererElem );
124 QPolygonF polygon( nPoints );
125 QPointF *d = polygon.data();
126 for (
int i = 0; i < nPoints; ++i )
128 d[i] = QPointF( padfX[i] * crData->
scaleX, padfY[i] * crData->
scaleY );
142 std::unique_ptr< QgsRasterBlock > outputBlock(
new QgsRasterBlock() );
143 if ( !
mInput || !mContourSymbol )
145 return outputBlock.release();
148 int inputWidth =
static_cast<int>( round( width / mDownscale ) );
149 int inputHeight =
static_cast<int>( round( height / mDownscale ) );
151 std::unique_ptr< QgsRasterBlock > inputBlock(
mInput->
block( mInputBand,
extent, inputWidth, inputHeight, feedback ) );
152 if ( !inputBlock || inputBlock->isEmpty() )
154 QgsDebugMsg( QStringLiteral(
"No raster data!" ) );
155 return outputBlock.release();
159 return outputBlock.release();
160 double *scanline =
reinterpret_cast<double *
>( inputBlock->bits() );
162 QImage img( width, height, QImage::Format_ARGB32_Premultiplied );
163 img.fill( Qt::transparent );
166 p.setRenderHint( QPainter::Antialiasing );
172 crData.
scaleX = width / double( inputWidth );
173 crData.
scaleY = height / double( inputHeight );
174 crData.
symbol = mContourSymbol.get();
183 double contourBase = 0.;
184 GDALContourGeneratorH cg = GDAL_CG_Create( inputBlock->width(), inputBlock->height(),
185 inputBlock->hasNoDataValue(), inputBlock->noDataValue(),
186 mContourInterval, contourBase,
188 for (
int i = 0; i < inputHeight; ++i )
193 GDAL_CG_FeedLine( cg, scanline );
194 scanline += inputWidth;
196 GDAL_CG_Destroy( cg );
204 outputBlock->setImage( &img );
205 return outputBlock.release();
211 if ( mInputBand != -1 )
213 bandList << mInputBand;
220 mContourSymbol.reset( symbol );
225 mContourIndexSymbol.reset( symbol );
void setInputBand(int band)
Sets the number of the input raster band.
void setDownscale(double scale)
Sets by how much the renderer will scale down the request to the data provider.
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 ...
The class is used as a container of context for various read/write operations on other objects.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
QgsRasterInterface * mInput
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
QMap< QString, QgsSymbol * > QgsSymbolMap
void setContourSymbol(QgsLineSymbol *symbol)
Sets the symbol used for contour lines. Takes ownership of the passed symbol.
double contourInterval() const
Returns the interval of contour lines generation.
Contains information about the context of a rendering operation.
CPLErr _rasterContourWriter(double dfLevel, int nPoints, double *padfX, double *padfY, void *ptr)
Abstract base class for all rendered symbols.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
Creates an instance of the renderer based on definition from XML (used by renderer registry)
void setContourIndexInterval(double interval)
Sets the interval of index contour lines (index contour lines are typical further apart and with a wi...
int inputBand() const
Returns the number of the input raster band.
A rectangle specified with double values.
QList< int > usesBands() const override
Returns a list of band numbers used by the renderer.
~QgsRasterContourRenderer() override
void setContourInterval(double interval)
Sets the interval of contour lines generation.
QgsRenderContext * context
void stopRender(QgsRenderContext &context)
Ends the rendering process.
Raster renderer pipe that applies colors to a raster.
Raster renderer that generates contours on the fly for a source raster band.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setContourIndexSymbol(QgsLineSymbol *symbol)
Sets the symbol of index contour lines.
void readXml(const QDomElement &rendererElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
void _writeXml(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXml method of subclasses)
A line symbol type, for rendering LineString and MultiLineString geometries.
void copyCommonProperties(const QgsRasterRenderer *other, bool copyMinMaxOrigin=true)
Copies common properties like opacity / transparency data from other renderer.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
QgsLineSymbol * indexSymbol
bool isCanceled() const
Tells whether the operation has been canceled already.
double downscale() const
Returns by how much the renderer will scale down the request to the data provider.
Base class for processing filters like renderers, reprojector, resampler etc.
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.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
virtual QgsRasterInterface * input() const
Current input.
Feedback object tailored for raster block reading.
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.
SymbolType type() const
Returns the symbol's type.
QgsRasterContourRenderer * clone() const override
Clone itself, create deep copy.
QgsRasterContourRenderer(QgsRasterInterface *input)
Creates a contour renderer.
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.
double contourIndexInterval() const
Returns the interval of index contour lines (index contour lines are typical further apart and with a...
virtual QgsRectangle extent() const
Gets the extent of the interface.
@ Float64
Sixty four bit floating point (double)