| 
    QGIS API Documentation
    3.26.3-Buenos Aires (65e4edfdad)
    
   | 
 
 
 
 
Go to the documentation of this file.
   38   renderer->mContourSymbol.reset( mContourSymbol ? mContourSymbol->clone() : 
nullptr );
 
   39   renderer->mContourIndexSymbol.reset( mContourIndexSymbol ? mContourIndexSymbol->clone() : 
nullptr );
 
   40   renderer->mContourInterval = mContourInterval;
 
   41   renderer->mContourIndexInterval = mContourIndexInterval;
 
   42   renderer->mInputBand = mInputBand;
 
   43   renderer->mDownscale = mDownscale;
 
   57   const int inputBand = elem.attribute( QStringLiteral( 
"band" ), QStringLiteral( 
"-1" ) ).toInt();
 
   58   const double contourInterval = elem.attribute( QStringLiteral( 
"contour-interval" ), QStringLiteral( 
"100" ) ).toDouble();
 
   59   const double contourIndexInterval = elem.attribute( QStringLiteral( 
"contour-index-interval" ), QStringLiteral( 
"0" ) ).toDouble();
 
   60   const double downscale = elem.attribute( QStringLiteral( 
"downscale" ), QStringLiteral( 
"4" ) ).toDouble();
 
   67   QDomElement symbolsElem = elem.firstChildElement( QStringLiteral( 
"symbols" ) );
 
   68   if ( !symbolsElem.isNull() )
 
   71     if ( symbolMap.contains( QStringLiteral( 
"contour" ) ) )
 
   73       QgsSymbol *symbol = symbolMap.take( QStringLiteral( 
"contour" ) );
 
   77     if ( symbolMap.contains( QStringLiteral( 
"index-contour" ) ) )
 
   79       QgsSymbol *symbol = symbolMap.take( QStringLiteral( 
"index-contour" ) );
 
   89   if ( parentElem.isNull() )
 
   94   QDomElement rasterRendererElem = doc.createElement( QStringLiteral( 
"rasterrenderer" ) );
 
   97   rasterRendererElem.setAttribute( QStringLiteral( 
"band" ), mInputBand );
 
   98   rasterRendererElem.setAttribute( QStringLiteral( 
"contour-interval" ), mContourInterval );
 
   99   rasterRendererElem.setAttribute( QStringLiteral( 
"contour-index-interval" ), mContourIndexInterval );
 
  100   rasterRendererElem.setAttribute( QStringLiteral( 
"downscale" ), mDownscale );
 
  103   symbols[QStringLiteral( 
"contour" )] = mContourSymbol.get();
 
  104   if ( mContourIndexSymbol )
 
  105     symbols[QStringLiteral( 
"index-contour" )] = mContourIndexSymbol.get();
 
  107   rasterRendererElem.appendChild( symbolsElem );
 
  109   parentElem.appendChild( rasterRendererElem );
 
  126   QPolygonF polygon( nPoints );
 
  127   QPointF *d = polygon.data();
 
  128   for ( 
int i = 0; i < nPoints; ++i )
 
  130     d[i] = QPointF( padfX[i] * crData->
scaleX, padfY[i] * crData->
scaleY );
 
  144   std::unique_ptr< QgsRasterBlock > outputBlock( 
new QgsRasterBlock() );
 
  145   if ( !
mInput || !mContourSymbol )
 
  147     return outputBlock.release();
 
  150   const int inputWidth = 
static_cast<int>( round( width / mDownscale ) );
 
  151   const int inputHeight = 
static_cast<int>( round( height / mDownscale ) );
 
  153   std::unique_ptr< QgsRasterBlock > inputBlock( 
mInput->
block( mInputBand, 
extent, inputWidth, inputHeight, feedback ) );
 
  154   if ( !inputBlock || inputBlock->isEmpty() )
 
  156     QgsDebugMsg( QStringLiteral( 
"No raster data!" ) );
 
  157     return outputBlock.release();
 
  161     return outputBlock.release();
 
  162   double *scanline = 
reinterpret_cast<double *
>( inputBlock->bits() );
 
  164   QImage img( width, height, QImage::Format_ARGB32_Premultiplied );
 
  165   img.fill( Qt::transparent );
 
  168   p.setRenderHint( QPainter::Antialiasing );
 
  174   crData.
scaleX = width / double( inputWidth );
 
  175   crData.
scaleY = height / double( inputHeight );
 
  176   crData.
symbol = mContourSymbol.get();
 
  185   const double contourBase = 0.;
 
  186   GDALContourGeneratorH cg = GDAL_CG_Create( inputBlock->width(), inputBlock->height(),
 
  187                              inputBlock->hasNoDataValue(), inputBlock->noDataValue(),
 
  188                              mContourInterval, contourBase,
 
  190   for ( 
int i = 0; i < inputHeight; ++i )
 
  195     GDAL_CG_FeedLine( cg, scanline );
 
  196     scanline += inputWidth;
 
  198   GDAL_CG_Destroy( cg );
 
  206   outputBlock->setImage( &img );
 
  207   return outputBlock.release();
 
  213   if ( mInputBand != -1 )
 
  215     bandList << mInputBand;
 
  222   QList<QgsLayerTreeModelLegendNode *> nodes;
 
  224   const QgsLegendSymbolItem contourItem( mContourSymbol.get(), QString::number( mContourInterval ), QStringLiteral( 
"contour" ) );
 
  227   if ( mContourIndexInterval > 0 )
 
  229     const QgsLegendSymbolItem indexItem( mContourIndexSymbol.get(), QString::number( mContourIndexInterval ), QStringLiteral( 
"index" ) );
 
  238   mContourSymbol.reset( symbol );
 
  243   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.
 
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
 
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.
 
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
 
QgsRenderContext * context
 
void stopRender(QgsRenderContext &context)
Ends the rendering process.
 
Qgis::SymbolType type() const
Returns the symbol's type.
 
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.
 
Layer tree node points to a map layer.
 
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)
 
@ Float64
Sixty four bit floating point (double)
 
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
 
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.
 
QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Creates a set of legend nodes representing the renderer.
 
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.
 
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...
 
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
 
virtual QgsRectangle extent() const
Gets the extent of the interface.