QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgspalettedrasterrenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspalettedrasterrenderer.cpp
3  -----------------------------
4  begin : December 2011
5  copyright : (C) 2011 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgsrastertransparency.h"
20 #include "qgsrasterviewport.h"
21 #include "qgssymbollayerutils.h"
22 #include "qgsstyleentityvisitor.h"
23 #include "qgsmessagelog.h"
24 #include "qgsrasteriterator.h"
25 
26 #include <QColor>
27 #include <QDomDocument>
28 #include <QDomElement>
29 #include <QImage>
30 #include <QVector>
31 #include <memory>
32 #include <set>
33 
34 const int QgsPalettedRasterRenderer::MAX_FLOAT_CLASSES = 65536;
35 
37  : QgsRasterRenderer( input, QStringLiteral( "paletted" ) )
38  , mBand( bandNumber )
39  , mClassData( classes )
40 {
41  updateArrays();
42 }
43 
45 {
46  QgsPalettedRasterRenderer *renderer = new QgsPalettedRasterRenderer( nullptr, mBand, mClassData );
47  if ( mSourceColorRamp )
48  renderer->setSourceColorRamp( mSourceColorRamp->clone() );
49 
50  renderer->copyCommonProperties( this );
51  return renderer;
52 }
53 
55 {
56  if ( elem.isNull() )
57  {
58  return nullptr;
59  }
60 
61  int bandNumber = elem.attribute( QStringLiteral( "band" ), QStringLiteral( "-1" ) ).toInt();
62  ClassData classData;
63 
64  QDomElement paletteElem = elem.firstChildElement( QStringLiteral( "colorPalette" ) );
65  if ( !paletteElem.isNull() )
66  {
67  QDomNodeList paletteEntries = paletteElem.elementsByTagName( QStringLiteral( "paletteEntry" ) );
68 
69  QDomElement entryElem;
70  int value;
71 
72  for ( int i = 0; i < paletteEntries.size(); ++i )
73  {
74  QColor color;
75  QString label;
76  entryElem = paletteEntries.at( i ).toElement();
77  value = entryElem.attribute( QStringLiteral( "value" ), QStringLiteral( "0" ) ).toDouble();
78  color = QColor( entryElem.attribute( QStringLiteral( "color" ), QStringLiteral( "#000000" ) ) );
79  color.setAlpha( entryElem.attribute( QStringLiteral( "alpha" ), QStringLiteral( "255" ) ).toInt() );
80  label = entryElem.attribute( QStringLiteral( "label" ) );
81  QgsDebugMsgLevel( QStringLiteral( "Value: %1, label: %2, color: %3" ).arg( value ).arg( label, entryElem.attribute( QStringLiteral( "color" ) ) ), 4 );
82  classData << Class( value, color, label );
83  }
84  }
85 
86  QgsPalettedRasterRenderer *r = new QgsPalettedRasterRenderer( input, bandNumber, classData );
87  r->readXml( elem );
88 
89  // try to load color ramp (optional)
90  QDomElement sourceColorRampElem = elem.firstChildElement( QStringLiteral( "colorramp" ) );
91  if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral( "name" ) ) == QLatin1String( "[source]" ) )
92  {
93  r->setSourceColorRamp( QgsSymbolLayerUtils::loadColorRamp( sourceColorRampElem ) );
94  }
95 
96  return r;
97 }
98 
100 {
101  return mClassData;
102 }
103 
104 QString QgsPalettedRasterRenderer::label( double idx ) const
105 {
106  const auto constMClassData = mClassData;
107  for ( const Class &c : constMClassData )
108  {
109  if ( c.value == idx )
110  return c.label;
111  }
112 
113  return QString();
114 }
115 
116 void QgsPalettedRasterRenderer::setLabel( double idx, const QString &label )
117 {
118  ClassData::iterator cIt = mClassData.begin();
119  for ( ; cIt != mClassData.end(); ++cIt )
120  {
121  if ( cIt->value == idx )
122  {
123  cIt->label = label;
124  return;
125  }
126  }
127 }
128 
129 QgsRasterBlock *QgsPalettedRasterRenderer::block( int, QgsRectangle const &extent, int width, int height, QgsRasterBlockFeedback *feedback )
130 {
131  std::unique_ptr< QgsRasterBlock > outputBlock( new QgsRasterBlock() );
132  if ( !mInput || mClassData.isEmpty() )
133  {
134  return outputBlock.release();
135  }
136 
137  std::shared_ptr< QgsRasterBlock > inputBlock( mInput->block( mBand, extent, width, height, feedback ) );
138 
139  if ( !inputBlock || inputBlock->isEmpty() )
140  {
141  QgsDebugMsg( QStringLiteral( "No raster data!" ) );
142  return outputBlock.release();
143  }
144 
145  double currentOpacity = mOpacity;
146 
147  //rendering is faster without considering user-defined transparency
148  bool hasTransparency = usesTransparency();
149 
150  std::shared_ptr< QgsRasterBlock > alphaBlock;
151 
152  if ( mAlphaBand > 0 && mAlphaBand != mBand )
153  {
154  alphaBlock.reset( mInput->block( mAlphaBand, extent, width, height, feedback ) );
155  if ( !alphaBlock || alphaBlock->isEmpty() )
156  {
157  return outputBlock.release();
158  }
159  }
160  else if ( mAlphaBand == mBand )
161  {
162  alphaBlock = inputBlock;
163  }
164 
165  if ( !outputBlock->reset( Qgis::ARGB32_Premultiplied, width, height ) )
166  {
167  return outputBlock.release();
168  }
169 
170  const QRgb myDefaultColor = renderColorForNodataPixel();
171 
172  //use direct data access instead of QgsRasterBlock::setValue
173  //because of performance
174  Q_ASSERT( outputBlock ); // to make cppcheck happy
175  unsigned int *outputData = ( unsigned int * )( outputBlock->bits() );
176 
177  qgssize rasterSize = ( qgssize )width * height;
178  bool isNoData = false;
179  for ( qgssize i = 0; i < rasterSize; ++i )
180  {
181  const double value = inputBlock->valueAndNoData( i, isNoData );
182  if ( isNoData )
183  {
184  outputData[i] = myDefaultColor;
185  continue;
186  }
187  if ( !mColors.contains( value ) )
188  {
189  outputData[i] = myDefaultColor;
190  continue;
191  }
192 
193  if ( !hasTransparency )
194  {
195  outputData[i] = mColors.value( value );
196  }
197  else
198  {
199  currentOpacity = mOpacity;
200  if ( mRasterTransparency )
201  {
202  currentOpacity = mRasterTransparency->alphaValue( value, mOpacity * 255 ) / 255.0;
203  }
204  if ( mAlphaBand > 0 )
205  {
206  currentOpacity *= alphaBlock->value( i ) / 255.0;
207  }
208 
209  QRgb c = mColors.value( value );
210  outputData[i] = qRgba( currentOpacity * qRed( c ), currentOpacity * qGreen( c ), currentOpacity * qBlue( c ), currentOpacity * qAlpha( c ) );
211  }
212  }
213 
214  return outputBlock.release();
215 }
216 
217 void QgsPalettedRasterRenderer::writeXml( QDomDocument &doc, QDomElement &parentElem ) const
218 {
219  if ( parentElem.isNull() )
220  {
221  return;
222  }
223 
224  QDomElement rasterRendererElem = doc.createElement( QStringLiteral( "rasterrenderer" ) );
225  _writeXml( doc, rasterRendererElem );
226 
227  rasterRendererElem.setAttribute( QStringLiteral( "band" ), mBand );
228  QDomElement colorPaletteElem = doc.createElement( QStringLiteral( "colorPalette" ) );
229  ClassData::const_iterator it = mClassData.constBegin();
230  for ( ; it != mClassData.constEnd(); ++it )
231  {
232  QColor color = it->color;
233  QDomElement colorElem = doc.createElement( QStringLiteral( "paletteEntry" ) );
234  colorElem.setAttribute( QStringLiteral( "value" ), it->value );
235  colorElem.setAttribute( QStringLiteral( "color" ), color.name() );
236  colorElem.setAttribute( QStringLiteral( "alpha" ), color.alpha() );
237  if ( !it->label.isEmpty() )
238  {
239  colorElem.setAttribute( QStringLiteral( "label" ), it->label );
240  }
241  colorPaletteElem.appendChild( colorElem );
242  }
243  rasterRendererElem.appendChild( colorPaletteElem );
244 
245  // save source color ramp
246  if ( mSourceColorRamp )
247  {
248  QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QStringLiteral( "[source]" ), mSourceColorRamp.get(), doc );
249  rasterRendererElem.appendChild( colorRampElem );
250  }
251 
252  parentElem.appendChild( rasterRendererElem );
253 }
254 
255 void QgsPalettedRasterRenderer::toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const
256 {
257  // create base structure
258  QgsRasterRenderer::toSld( doc, element, props );
259 
260  // look for RasterSymbolizer tag
261  QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
262  if ( elements.size() == 0 )
263  return;
264 
265  // there SHOULD be only one
266  QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();
267 
268  // add Channel Selection tags
269  QDomElement channelSelectionElem = doc.createElement( QStringLiteral( "sld:ChannelSelection" ) );
270  rasterSymbolizerElem.appendChild( channelSelectionElem );
271 
272  // for the mapped band
273  QDomElement channelElem = doc.createElement( QStringLiteral( "sld:GrayChannel" ) );
274  channelSelectionElem.appendChild( channelElem );
275 
276  // set band
277  QDomElement sourceChannelNameElem = doc.createElement( QStringLiteral( "sld:SourceChannelName" ) );
278  sourceChannelNameElem.appendChild( doc.createTextNode( QString::number( band() ) ) );
279  channelElem.appendChild( sourceChannelNameElem );
280 
281  // add ColorMap tag
282  QDomElement colorMapElem = doc.createElement( QStringLiteral( "sld:ColorMap" ) );
283  colorMapElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "values" ) );
284  if ( this->classes().size() >= 255 )
285  colorMapElem.setAttribute( QStringLiteral( "extended" ), QStringLiteral( "true" ) );
286  rasterSymbolizerElem.appendChild( colorMapElem );
287 
288  // for each color set a ColorMapEntry tag nested into "sld:ColorMap" tag
289  // e.g. <ColorMapEntry color="#EEBE2F" quantity="-300" label="label" opacity="0"/>
290  QList<QgsPalettedRasterRenderer::Class> classes = this->classes();
291  QList<QgsPalettedRasterRenderer::Class>::const_iterator classDataIt = classes.constBegin();
292  for ( ; classDataIt != classes.constEnd(); ++classDataIt )
293  {
294  QDomElement colorMapEntryElem = doc.createElement( QStringLiteral( "sld:ColorMapEntry" ) );
295  colorMapElem.appendChild( colorMapEntryElem );
296 
297  // set colorMapEntryElem attributes
298  colorMapEntryElem.setAttribute( QStringLiteral( "color" ), classDataIt->color.name() );
299  colorMapEntryElem.setAttribute( QStringLiteral( "quantity" ), QString::number( classDataIt->value ) );
300  colorMapEntryElem.setAttribute( QStringLiteral( "label" ), classDataIt->label );
301  if ( classDataIt->color.alphaF() != 1.0 )
302  {
303  colorMapEntryElem.setAttribute( QStringLiteral( "opacity" ), QString::number( classDataIt->color.alphaF() ) );
304  }
305  }
306 }
307 
309 {
310  if ( mSourceColorRamp )
311  {
312  QgsStyleColorRampEntity entity( mSourceColorRamp.get() );
313  if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity ) ) )
314  return false;
315  }
316 
317  return true;
318 }
319 
320 void QgsPalettedRasterRenderer::legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems ) const
321 {
322  ClassData::const_iterator it = mClassData.constBegin();
323  for ( ; it != mClassData.constEnd(); ++it )
324  {
325  QString lab = it->label.isEmpty() ? QString::number( it->value ) : it->label;
326  symbolItems << qMakePair( lab, it->color );
327  }
328 }
329 
331 {
332  QList<int> bandList;
333  if ( mBand != -1 )
334  {
335  bandList << mBand;
336  }
337  return bandList;
338 }
339 
341 {
342  mSourceColorRamp.reset( ramp );
343 }
344 
346 {
347  return mSourceColorRamp.get();
348 }
349 
350 QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table )
351 {
352  QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = table.constBegin();
354  for ( ; colorIt != table.constEnd(); ++colorIt )
355  {
356  int idx = ( int )( colorIt->value );
357  classes << QgsPalettedRasterRenderer::Class( idx, colorIt->color, colorIt->label );
358  }
359  return classes;
360 }
361 
363 {
365 
366  QRegularExpression linePartRx( QStringLiteral( "[\\s,:]+" ) );
367 
368  QStringList parts = string.split( '\n', QString::SkipEmptyParts );
369  const auto constParts = parts;
370  for ( const QString &part : constParts )
371  {
372  QStringList lineParts = part.split( linePartRx, QString::SkipEmptyParts );
373  bool ok = false;
374  switch ( lineParts.count() )
375  {
376  case 1:
377  {
378  int value = lineParts.at( 0 ).toInt( &ok );
379  if ( !ok )
380  continue;
381 
382  classes << Class( value );
383  break;
384  }
385 
386  case 2:
387  {
388  int value = lineParts.at( 0 ).toInt( &ok );
389  if ( !ok )
390  continue;
391 
392  QColor c( lineParts.at( 1 ) );
393 
394  classes << Class( value, c );
395  break;
396  }
397 
398  default:
399  {
400  if ( lineParts.count() < 4 )
401  continue;
402 
403  int value = lineParts.at( 0 ).toInt( &ok );
404  if ( !ok )
405  continue;
406 
407  bool rOk = false;
408  double r = lineParts.at( 1 ).toDouble( &rOk );
409  bool gOk = false;
410  double g = lineParts.at( 2 ).toDouble( &gOk );
411  bool bOk = false;
412  double b = lineParts.at( 3 ).toDouble( &bOk );
413 
414  QColor c;
415  if ( rOk && gOk && bOk )
416  {
417  c = QColor( r, g, b );
418  }
419 
420  if ( lineParts.count() >= 5 )
421  {
422  double alpha = lineParts.at( 4 ).toDouble( &ok );
423  if ( ok )
424  c.setAlpha( alpha );
425  }
426 
427  QString label;
428  if ( lineParts.count() > 5 )
429  {
430  label = lineParts.mid( 5 ).join( ' ' );
431  }
432 
433  classes << Class( value, c, label );
434  break;
435  }
436  }
437 
438  }
439  return classes;
440 }
441 
443 {
444  QFile inputFile( path );
445  QString input;
446  if ( inputFile.open( QIODevice::ReadOnly ) )
447  {
448  QTextStream in( &inputFile );
449  input = in.readAll();
450  inputFile.close();
451  }
452  return classDataFromString( input );
453 }
454 
456 {
457  QStringList out;
458  // must be sorted
460  std::sort( cd.begin(), cd.end(), []( const Class & a, const Class & b ) -> bool
461  {
462  return a.value < b.value;
463  } );
464 
465  const auto constCd = cd;
466  for ( const Class &c : constCd )
467  {
468  out << QStringLiteral( "%1 %2 %3 %4 %5 %6" ).arg( c.value ).arg( c.color.red() )
469  .arg( c.color.green() ).arg( c.color.blue() ).arg( c.color.alpha() ).arg( c.label );
470  }
471  return out.join( '\n' );
472 }
473 
475 {
476  if ( !raster )
477  return ClassData();
478 
479  ClassData data;
480  qlonglong numClasses = 0;
481 
482  if ( feedback )
483  feedback->setProgress( 0 );
484 
485  // Collect unique values for float rasters
486  if ( raster->dataType( bandNumber ) == Qgis::DataType::Float32 || raster->dataType( bandNumber ) == Qgis::DataType::Float64 )
487  {
488 
489  if ( feedback && feedback->isCanceled() )
490  {
491  return data;
492  }
493 
494  std::set<double> values;
495 
498 
499  QgsRasterIterator iter( raster );
500  iter.startRasterRead( bandNumber, raster->xSize(), raster->ySize(), raster->extent(), feedback );
501 
502  int nbBlocksWidth = static_cast< int >( std::ceil( 1.0 * raster->ySize() / maxWidth ) );
503  int nbBlocksHeight = static_cast< int >( std::ceil( 1.0 * raster->ySize() / maxHeight ) );
504  int nbBlocks = nbBlocksWidth * nbBlocksHeight;
505 
506  int iterLeft = 0;
507  int iterTop = 0;
508  int iterCols = 0;
509  int iterRows = 0;
510  std::unique_ptr< QgsRasterBlock > rasterBlock;
511  QgsRectangle blockExtent;
512  bool isNoData = false;
513  while ( iter.readNextRasterPart( bandNumber, iterCols, iterRows, rasterBlock, iterLeft, iterTop, &blockExtent ) )
514  {
515  if ( feedback )
516  feedback->setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
517 
518  if ( feedback && feedback->isCanceled() )
519  break;
520 
521  for ( int row = 0; row < iterRows; row++ )
522  {
523  if ( feedback && feedback->isCanceled() )
524  break;
525 
526  for ( int column = 0; column < iterCols; column++ )
527  {
528  if ( feedback && feedback->isCanceled() )
529  break;
530 
531  const double currentValue = rasterBlock->valueAndNoData( row, column, isNoData );
532  if ( numClasses >= MAX_FLOAT_CLASSES )
533  {
534  QgsMessageLog::logMessage( QStringLiteral( "Number of classes exceeded maximum (%1)." ).arg( MAX_FLOAT_CLASSES ), QStringLiteral( "Raster" ) );
535  break;
536  }
537  if ( !isNoData && values.find( currentValue ) == values.end() )
538  {
539  values.insert( currentValue );
540  data.push_back( Class( currentValue, QColor(), QLocale().toString( currentValue ) ) );
541  numClasses++;
542  }
543  }
544  }
545  }
546  }
547  else
548  {
549  // get min and max value from raster
550  QgsRasterBandStats stats = raster->bandStatistics( bandNumber, QgsRasterBandStats::Min | QgsRasterBandStats::Max, QgsRectangle(), 0, feedback );
551  if ( feedback && feedback->isCanceled() )
552  return ClassData();
553 
554  double min = stats.minimumValue;
555  double max = stats.maximumValue;
556  // need count of every individual value
557  int bins = std::ceil( max - min ) + 1;
558  if ( bins <= 0 )
559  return ClassData();
560 
561  QgsRasterHistogram histogram = raster->histogram( bandNumber, bins, min, max, QgsRectangle(), 0, false, feedback );
562  if ( feedback && feedback->isCanceled() )
563  return ClassData();
564 
565  double interval = ( histogram.maximum - histogram.minimum + 1 ) / histogram.binCount;
566  double currentValue = histogram.minimum;
567  for ( int idx = 0; idx < histogram.binCount; ++idx )
568  {
569  int count = histogram.histogramVector.at( idx );
570  if ( count > 0 )
571  {
572  data << Class( currentValue, QColor(), QLocale().toString( currentValue ) );
573  numClasses++;
574  }
575  currentValue += interval;
576  }
577  }
578 
579  // assign colors from ramp
580  if ( ramp )
581  {
582  int i = 0;
583 
584  if ( QgsRandomColorRamp *randomRamp = dynamic_cast<QgsRandomColorRamp *>( ramp ) )
585  {
586  //ramp is a random colors ramp, so inform it of the total number of required colors
587  //this allows the ramp to pregenerate a set of visually distinctive colors
588  randomRamp->setTotalColorCount( data.count() );
589  }
590 
591  if ( numClasses > 1 )
592  numClasses -= 1; //avoid duplicate first color
593 
594  QgsPalettedRasterRenderer::ClassData::iterator cIt = data.begin();
595  for ( ; cIt != data.end(); ++cIt )
596  {
597  if ( feedback )
598  {
599  // Show no less than 1%, then the max between class fill and real progress
600  feedback->setProgress( std::max<int>( 1, 100 * ( i + 1 ) / numClasses ) );
601  }
602  cIt->color = ramp->color( i / static_cast<double>( numClasses ) );
603  i++;
604  }
605  }
606  return data;
607 }
608 
609 void QgsPalettedRasterRenderer::updateArrays()
610 {
611  mColors.clear();
612  int i = 0;
613  ClassData::const_iterator it = mClassData.constBegin();
614  for ( ; it != mClassData.constEnd(); ++it )
615  {
616  mColors[it->value] = qPremultiply( it->color.rgba() );
617  i++;
618  }
619 }
QgsPalettedRasterRenderer::classDataFromString
static QgsPalettedRasterRenderer::ClassData classDataFromString(const QString &string)
Converts a string containing a color table or class data to to paletted renderer class data.
Definition: qgspalettedrasterrenderer.cpp:362
QgsPalettedRasterRenderer::ClassData
QList< QgsPalettedRasterRenderer::Class > ClassData
Map of value to class properties.
Definition: qgspalettedrasterrenderer.h:59
QgsColorRamp
Abstract base class for color ramps.
Definition: qgscolorramp.h:32
QgsFeedback::setProgress
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:62
QgsRasterHistogram::histogramVector
QgsRasterHistogram::HistogramVector histogramVector
Stores the histogram for a given layer.
Definition: qgsrasterhistogram.h:71
QgsPalettedRasterRenderer::sourceColorRamp
QgsColorRamp * sourceColorRamp() const
Gets the source color ramp.
Definition: qgspalettedrasterrenderer.cpp:345
QgsRasterInterface::bandStatistics
virtual QgsRasterBandStats bandStatistics(int bandNo, int stats=QgsRasterBandStats::All, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, QgsRasterBlockFeedback *feedback=nullptr)
Returns the band statistics.
Definition: qgsrasterinterface.cpp:116
QgsRasterInterface::mInput
QgsRasterInterface * mInput
Definition: qgsrasterinterface.h:467
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsRasterTransparency::alphaValue
int alphaValue(double value, int globalTransparency=255) const
Returns the transparency value for a single value pixel.
Definition: qgsrastertransparency.cpp:74
qgsrasterviewport.h
QgsPalettedRasterRenderer::setLabel
void setLabel(double idx, const QString &label)
Set category label.
Definition: qgspalettedrasterrenderer.cpp:116
QgsRasterBandStats
The RasterBandStats struct is a container for statistics about a single raster band.
Definition: qgsrasterbandstats.h:35
QgsStyleColorRampEntity
A color ramp entity for QgsStyle databases.
Definition: qgsstyle.h:1233
qgssymbollayerutils.h
QgsPalettedRasterRenderer::clone
QgsPalettedRasterRenderer * clone() const override
Clone itself, create deep copy.
Definition: qgspalettedrasterrenderer.cpp:44
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
QgsRasterRenderer::toSld
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const
Used from subclasses to create SLD Rule elements following SLD v1.0 specs.
Definition: qgsrasterrenderer.cpp:175
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsPalettedRasterRenderer::colorTableToClassData
static QgsPalettedRasterRenderer::ClassData colorTableToClassData(const QList< QgsColorRampShader::ColorRampItem > &table)
Converts a raster color table to paletted renderer class data.
Definition: qgspalettedrasterrenderer.cpp:350
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsStyleEntityVisitorInterface::StyleLeaf
Contains information relating to the style entity currently being visited.
Definition: qgsstyleentityvisitor.h:61
QgsPalettedRasterRenderer::legendSymbologyItems
void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const override
Gets symbology items if provided by renderer.
Definition: qgspalettedrasterrenderer.cpp:320
QgsPalettedRasterRenderer::block
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
Definition: qgspalettedrasterrenderer.cpp:129
QgsRandomColorRamp
Totally random color ramp.
Definition: qgscolorramp.h:455
QgsPalettedRasterRenderer::accept
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Definition: qgspalettedrasterrenderer.cpp:308
qgsrasteriterator.h
QgsPalettedRasterRenderer::setSourceColorRamp
void setSourceColorRamp(QgsColorRamp *ramp)
Set the source color ramp.
Definition: qgspalettedrasterrenderer.cpp:340
QgsRasterBandStats::maximumValue
double maximumValue
The maximum cell value in the raster band.
Definition: qgsrasterbandstats.h:88
QgsPalettedRasterRenderer::create
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
Definition: qgspalettedrasterrenderer.cpp:54
QgsPalettedRasterRenderer::usesBands
QList< int > usesBands() const override
Returns a list of band numbers used by the renderer.
Definition: qgspalettedrasterrenderer.cpp:330
QgsRasterHistogram::minimum
double minimum
The minimum histogram value.
Definition: qgsrasterhistogram.h:77
qgspalettedrasterrenderer.h
QgsRasterInterface::xSize
virtual int xSize() const
Gets raster size.
Definition: qgsrasterinterface.h:241
QgsRasterRenderer
Raster renderer pipe that applies colors to a raster.
Definition: qgsrasterrenderer.h:39
QgsPalettedRasterRenderer::classDataFromRaster
static QgsPalettedRasterRenderer::ClassData classDataFromRaster(QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp=nullptr, QgsRasterBlockFeedback *feedback=nullptr)
Generates class data from a raster, for the specified bandNumber.
Definition: qgspalettedrasterrenderer.cpp:474
QgsRasterInterface::dataType
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
QgsSymbolLayerUtils::saveColorRamp
static QDomElement saveColorRamp(const QString &name, QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
Definition: qgssymbollayerutils.cpp:3112
QgsRasterRenderer::mRasterTransparency
QgsRasterTransparency * mRasterTransparency
Raster transparency per color or value. Overwrites global alpha value.
Definition: qgsrasterrenderer.h:168
QgsRasterRenderer::readXml
void readXml(const QDomElement &rendererElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
Definition: qgsrasterrenderer.cpp:134
QgsRasterIterator::startRasterRead
void startRasterRead(int bandNumber, qgssize nCols, qgssize nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback=nullptr)
Start reading of raster band.
Definition: qgsrasteriterator.cpp:38
QgsPalettedRasterRenderer::band
int band() const
Returns the raster band used for rendering the raster.
Definition: qgspalettedrasterrenderer.h:100
QgsRasterRenderer::_writeXml
void _writeXml(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXml method of subclasses)
Definition: qgsrasterrenderer.cpp:104
QgsRasterIterator::DEFAULT_MAXIMUM_TILE_HEIGHT
static const int DEFAULT_MAXIMUM_TILE_HEIGHT
Default maximum tile height.
Definition: qgsrasteriterator.h:151
QgsPalettedRasterRenderer::Class
Properties of a single value class.
Definition: qgspalettedrasterrenderer.h:41
QgsRasterRenderer::copyCommonProperties
void copyCommonProperties(const QgsRasterRenderer *other, bool copyMinMaxOrigin=true)
Copies common properties like opacity / transparency data from other renderer.
Definition: qgsrasterrenderer.cpp:162
QgsRasterBandStats::Min
@ Min
Definition: qgsrasterbandstats.h:40
QgsPalettedRasterRenderer::toSld
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const override
Used from subclasses to create SLD Rule elements following SLD v1.0 specs.
Definition: qgspalettedrasterrenderer.cpp:255
QgsRasterRenderer::usesTransparency
bool usesTransparency() const
Definition: qgsrasterrenderer.cpp:89
QgsPalettedRasterRenderer::classDataToString
static QString classDataToString(const QgsPalettedRasterRenderer::ClassData &classes)
Converts classes to a string representation, using the .clr/gdal color table file format.
Definition: qgspalettedrasterrenderer.cpp:455
QgsRasterHistogram::binCount
int binCount
Number of bins (intervals,buckets) in histogram.
Definition: qgsrasterhistogram.h:60
QgsPalettedRasterRenderer
Renderer for paletted raster images.
Definition: qgspalettedrasterrenderer.h:36
QgsRasterIterator
Iterator for sequentially processing raster cells.
Definition: qgsrasteriterator.h:35
qgsrastertransparency.h
QgsRasterRenderer::mAlphaBand
int mAlphaBand
Read alpha value from band.
Definition: qgsrasterrenderer.h:174
QgsRasterIterator::readNextRasterPart
bool readNextRasterPart(int bandNumber, int &nCols, int &nRows, QgsRasterBlock **block, int &topLeftCol, int &topLeftRow)
Fetches next part of raster data, caller takes ownership of the block and caller should delete the bl...
Definition: qgsrasteriterator.cpp:65
QgsPalettedRasterRenderer::QgsPalettedRasterRenderer
QgsPalettedRasterRenderer(QgsRasterInterface *input, int bandNumber, const ClassData &classes)
Constructor for QgsPalettedRasterRenderer.
Definition: qgspalettedrasterrenderer.cpp:36
QgsSymbolLayerUtils::loadColorRamp
static QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
Definition: qgssymbollayerutils.cpp:3087
QgsRasterInterface::ySize
virtual int ySize() const
Definition: qgsrasterinterface.h:242
QgsRasterBandStats::minimumValue
double minimumValue
The minimum cell value in the raster band.
Definition: qgsrasterbandstats.h:94
QgsFeedback::isCanceled
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:53
QgsRasterBandStats::Max
@ Max
Definition: qgsrasterbandstats.h:41
QgsPalettedRasterRenderer::writeXml
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
Definition: qgspalettedrasterrenderer.cpp:217
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
Qgis::ARGB32_Premultiplied
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
Definition: qgis.h:116
QgsRasterInterface
Base class for processing filters like renderers, reprojector, resampler etc.
Definition: qgsrasterinterface.h:117
QgsRasterInterface::histogram
virtual QgsRasterHistogram histogram(int bandNo, int binCount=0, double minimum=std::numeric_limits< double >::quiet_NaN(), double maximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, bool includeOutOfRange=false, QgsRasterBlockFeedback *feedback=nullptr)
Returns a band histogram.
Definition: qgsrasterinterface.cpp:404
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsRasterHistogram
The QgsRasterHistogram is a container for histogram of a single raster band.
Definition: qgsrasterhistogram.h:34
QgsRasterRenderer::renderColorForNodataPixel
QRgb renderColorForNodataPixel() const
Returns the color for the renderer to use to represent nodata pixels.
Definition: qgsrasterrenderer.cpp:126
QgsRasterInterface::input
virtual QgsRasterInterface * input() const
Current input.
Definition: qgsrasterinterface.h:269
QgsRasterBlockFeedback
Feedback object tailored for raster block reading.
Definition: qgsrasterinterface.h:41
QgsRasterIterator::DEFAULT_MAXIMUM_TILE_WIDTH
static const int DEFAULT_MAXIMUM_TILE_WIDTH
Default maximum tile width.
Definition: qgsrasteriterator.h:148
QgsColorRamp::color
virtual QColor color(double value) const =0
Returns the color corresponding to a specified value.
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
QgsRasterRenderer::mOpacity
double mOpacity
Global alpha value (0-1)
Definition: qgsrasterrenderer.h:166
QgsStyleEntityVisitorInterface::visit
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
Definition: qgsstyleentityvisitor.h:153
QgsPalettedRasterRenderer::classes
ClassData classes() const
Returns a map of value to classes (colors) used by the renderer.
Definition: qgspalettedrasterrenderer.cpp:99
QgsRasterInterface::block
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.
QgsRasterHistogram::maximum
double maximum
The maximum histogram value.
Definition: qgsrasterhistogram.h:74
QgsPalettedRasterRenderer::classDataFromFile
static QgsPalettedRasterRenderer::ClassData classDataFromFile(const QString &path)
Opens a color table file and returns corresponding paletted renderer class data.
Definition: qgspalettedrasterrenderer.cpp:442
QgsPalettedRasterRenderer::label
QString label(double idx) const
Returns optional category label.
Definition: qgspalettedrasterrenderer.cpp:104
QgsRasterBlock
Raster data container.
Definition: qgsrasterblock.h:37
QgsRasterInterface::extent
virtual QgsRectangle extent() const
Gets the extent of the interface.
Definition: qgsrasterinterface.h:229
qgsstyleentityvisitor.h
qgsmessagelog.h
qgssize
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
Definition: qgis.h:768