QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
24 #include <QColor>
25 #include <QDomDocument>
26 #include <QDomElement>
27 #include <QImage>
28 #include <QVector>
29 #include <memory>
30 
32  : QgsRasterRenderer( input, QStringLiteral( "paletted" ) )
33  , mBand( bandNumber )
34  , mClassData( classes )
35 {
36  updateArrays();
37 }
38 
40 {
41  QgsPalettedRasterRenderer *renderer = new QgsPalettedRasterRenderer( nullptr, mBand, mClassData );
42  if ( mSourceColorRamp )
43  renderer->setSourceColorRamp( mSourceColorRamp->clone() );
44 
45  renderer->copyCommonProperties( this );
46  return renderer;
47 }
48 
50 {
51  if ( elem.isNull() )
52  {
53  return nullptr;
54  }
55 
56  int bandNumber = elem.attribute( QStringLiteral( "band" ), QStringLiteral( "-1" ) ).toInt();
57  ClassData classData;
58 
59  QDomElement paletteElem = elem.firstChildElement( QStringLiteral( "colorPalette" ) );
60  if ( !paletteElem.isNull() )
61  {
62  QDomNodeList paletteEntries = paletteElem.elementsByTagName( QStringLiteral( "paletteEntry" ) );
63 
64  QDomElement entryElem;
65  int value;
66 
67  for ( int i = 0; i < paletteEntries.size(); ++i )
68  {
69  QColor color;
70  QString label;
71  entryElem = paletteEntries.at( i ).toElement();
72  value = static_cast<int>( entryElem.attribute( QStringLiteral( "value" ), QStringLiteral( "0" ) ).toDouble() );
73  QgsDebugMsgLevel( entryElem.attribute( "color", "#000000" ), 4 );
74  color = QColor( entryElem.attribute( QStringLiteral( "color" ), QStringLiteral( "#000000" ) ) );
75  color.setAlpha( entryElem.attribute( QStringLiteral( "alpha" ), QStringLiteral( "255" ) ).toInt() );
76  label = entryElem.attribute( QStringLiteral( "label" ) );
77  classData << Class( value, color, label );
78  }
79  }
80 
81  QgsPalettedRasterRenderer *r = new QgsPalettedRasterRenderer( input, bandNumber, classData );
82  r->readXml( elem );
83 
84  // try to load color ramp (optional)
85  QDomElement sourceColorRampElem = elem.firstChildElement( QStringLiteral( "colorramp" ) );
86  if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral( "name" ) ) == QLatin1String( "[source]" ) )
87  {
88  r->setSourceColorRamp( QgsSymbolLayerUtils::loadColorRamp( sourceColorRampElem ) );
89  }
90 
91  return r;
92 }
93 
95 {
96  return mClassData;
97 }
98 
99 QString QgsPalettedRasterRenderer::label( int idx ) const
100 {
101  const auto constMClassData = mClassData;
102  for ( const Class &c : constMClassData )
103  {
104  if ( c.value == idx )
105  return c.label;
106  }
107 
108  return QString();
109 }
110 
111 void QgsPalettedRasterRenderer::setLabel( int idx, const QString &label )
112 {
113  ClassData::iterator cIt = mClassData.begin();
114  for ( ; cIt != mClassData.end(); ++cIt )
115  {
116  if ( cIt->value == idx )
117  {
118  cIt->label = label;
119  return;
120  }
121  }
122 }
123 
124 QgsRasterBlock *QgsPalettedRasterRenderer::block( int, QgsRectangle const &extent, int width, int height, QgsRasterBlockFeedback *feedback )
125 {
126  std::unique_ptr< QgsRasterBlock > outputBlock( new QgsRasterBlock() );
127  if ( !mInput || mClassData.isEmpty() )
128  {
129  return outputBlock.release();
130  }
131 
132  std::shared_ptr< QgsRasterBlock > inputBlock( mInput->block( mBand, extent, width, height, feedback ) );
133 
134  if ( !inputBlock || inputBlock->isEmpty() )
135  {
136  QgsDebugMsg( QStringLiteral( "No raster data!" ) );
137  return outputBlock.release();
138  }
139 
140  double currentOpacity = mOpacity;
141 
142  //rendering is faster without considering user-defined transparency
143  bool hasTransparency = usesTransparency();
144 
145  std::shared_ptr< QgsRasterBlock > alphaBlock;
146 
147  if ( mAlphaBand > 0 && mAlphaBand != mBand )
148  {
149  alphaBlock.reset( mInput->block( mAlphaBand, extent, width, height, feedback ) );
150  if ( !alphaBlock || alphaBlock->isEmpty() )
151  {
152  return outputBlock.release();
153  }
154  }
155  else if ( mAlphaBand == mBand )
156  {
157  alphaBlock = inputBlock;
158  }
159 
160  if ( !outputBlock->reset( Qgis::ARGB32_Premultiplied, width, height ) )
161  {
162  return outputBlock.release();
163  }
164 
165  const QRgb myDefaultColor = renderColorForNodataPixel();
166 
167  //use direct data access instead of QgsRasterBlock::setValue
168  //because of performance
169  Q_ASSERT( outputBlock ); // to make cppcheck happy
170  unsigned int *outputData = ( unsigned int * )( outputBlock->bits() );
171 
172  qgssize rasterSize = ( qgssize )width * height;
173  bool isNoData = false;
174  for ( qgssize i = 0; i < rasterSize; ++i )
175  {
176  const double value = inputBlock->valueAndNoData( i, isNoData );
177  if ( isNoData )
178  {
179  outputData[i] = myDefaultColor;
180  continue;
181  }
182  int val = static_cast< int >( value );
183  if ( !mColors.contains( val ) )
184  {
185  outputData[i] = myDefaultColor;
186  continue;
187  }
188 
189  if ( !hasTransparency )
190  {
191  outputData[i] = mColors.value( val );
192  }
193  else
194  {
195  currentOpacity = mOpacity;
196  if ( mRasterTransparency )
197  {
198  currentOpacity = mRasterTransparency->alphaValue( val, mOpacity * 255 ) / 255.0;
199  }
200  if ( mAlphaBand > 0 )
201  {
202  currentOpacity *= alphaBlock->value( i ) / 255.0;
203  }
204 
205  QRgb c = mColors.value( val );
206  outputData[i] = qRgba( currentOpacity * qRed( c ), currentOpacity * qGreen( c ), currentOpacity * qBlue( c ), currentOpacity * qAlpha( c ) );
207  }
208  }
209 
210  return outputBlock.release();
211 }
212 
213 void QgsPalettedRasterRenderer::writeXml( QDomDocument &doc, QDomElement &parentElem ) const
214 {
215  if ( parentElem.isNull() )
216  {
217  return;
218  }
219 
220  QDomElement rasterRendererElem = doc.createElement( QStringLiteral( "rasterrenderer" ) );
221  _writeXml( doc, rasterRendererElem );
222 
223  rasterRendererElem.setAttribute( QStringLiteral( "band" ), mBand );
224  QDomElement colorPaletteElem = doc.createElement( QStringLiteral( "colorPalette" ) );
225  ClassData::const_iterator it = mClassData.constBegin();
226  for ( ; it != mClassData.constEnd(); ++it )
227  {
228  QColor color = it->color;
229  QDomElement colorElem = doc.createElement( QStringLiteral( "paletteEntry" ) );
230  colorElem.setAttribute( QStringLiteral( "value" ), it->value );
231  colorElem.setAttribute( QStringLiteral( "color" ), color.name() );
232  colorElem.setAttribute( QStringLiteral( "alpha" ), color.alpha() );
233  if ( !it->label.isEmpty() )
234  {
235  colorElem.setAttribute( QStringLiteral( "label" ), it->label );
236  }
237  colorPaletteElem.appendChild( colorElem );
238  }
239  rasterRendererElem.appendChild( colorPaletteElem );
240 
241  // save source color ramp
242  if ( mSourceColorRamp )
243  {
244  QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QStringLiteral( "[source]" ), mSourceColorRamp.get(), doc );
245  rasterRendererElem.appendChild( colorRampElem );
246  }
247 
248  parentElem.appendChild( rasterRendererElem );
249 }
250 
251 void QgsPalettedRasterRenderer::toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const
252 {
253  // create base structure
254  QgsRasterRenderer::toSld( doc, element, props );
255 
256  // look for RasterSymbolizer tag
257  QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
258  if ( elements.size() == 0 )
259  return;
260 
261  // there SHOULD be only one
262  QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();
263 
264  // add Channel Selection tags
265  QDomElement channelSelectionElem = doc.createElement( QStringLiteral( "sld:ChannelSelection" ) );
266  rasterSymbolizerElem.appendChild( channelSelectionElem );
267 
268  // for the mapped band
269  QDomElement channelElem = doc.createElement( QStringLiteral( "sld:GrayChannel" ) );
270  channelSelectionElem.appendChild( channelElem );
271 
272  // set band
273  QDomElement sourceChannelNameElem = doc.createElement( QStringLiteral( "sld:SourceChannelName" ) );
274  sourceChannelNameElem.appendChild( doc.createTextNode( QString::number( band() ) ) );
275  channelElem.appendChild( sourceChannelNameElem );
276 
277  // add ColorMap tag
278  QDomElement colorMapElem = doc.createElement( QStringLiteral( "sld:ColorMap" ) );
279  colorMapElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "values" ) );
280  if ( this->classes().size() >= 255 )
281  colorMapElem.setAttribute( QStringLiteral( "extended" ), QStringLiteral( "true" ) );
282  rasterSymbolizerElem.appendChild( colorMapElem );
283 
284  // for each color set a ColorMapEntry tag nested into "sld:ColorMap" tag
285  // e.g. <ColorMapEntry color="#EEBE2F" quantity="-300" label="label" opacity="0"/>
286  QList<QgsPalettedRasterRenderer::Class> classes = this->classes();
287  QList<QgsPalettedRasterRenderer::Class>::const_iterator classDataIt = classes.constBegin();
288  for ( ; classDataIt != classes.constEnd(); ++classDataIt )
289  {
290  QDomElement colorMapEntryElem = doc.createElement( QStringLiteral( "sld:ColorMapEntry" ) );
291  colorMapElem.appendChild( colorMapEntryElem );
292 
293  // set colorMapEntryElem attributes
294  colorMapEntryElem.setAttribute( QStringLiteral( "color" ), classDataIt->color.name() );
295  colorMapEntryElem.setAttribute( QStringLiteral( "quantity" ), QString::number( classDataIt->value ) );
296  colorMapEntryElem.setAttribute( QStringLiteral( "label" ), classDataIt->label );
297  if ( classDataIt->color.alphaF() != 1.0 )
298  {
299  colorMapEntryElem.setAttribute( QStringLiteral( "opacity" ), QString::number( classDataIt->color.alphaF() ) );
300  }
301  }
302 }
303 
305 {
306  if ( mSourceColorRamp )
307  {
308  QgsStyleColorRampEntity entity( mSourceColorRamp.get() );
309  if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity ) ) )
310  return false;
311  }
312 
313  return true;
314 }
315 
316 void QgsPalettedRasterRenderer::legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems ) const
317 {
318  ClassData::const_iterator it = mClassData.constBegin();
319  for ( ; it != mClassData.constEnd(); ++it )
320  {
321  QString lab = it->label.isEmpty() ? QString::number( it->value ) : it->label;
322  symbolItems << qMakePair( lab, it->color );
323  }
324 }
325 
327 {
328  QList<int> bandList;
329  if ( mBand != -1 )
330  {
331  bandList << mBand;
332  }
333  return bandList;
334 }
335 
337 {
338  mSourceColorRamp.reset( ramp );
339 }
340 
342 {
343  return mSourceColorRamp.get();
344 }
345 
346 QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table )
347 {
348  QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = table.constBegin();
350  for ( ; colorIt != table.constEnd(); ++colorIt )
351  {
352  int idx = ( int )( colorIt->value );
353  classes << QgsPalettedRasterRenderer::Class( idx, colorIt->color, colorIt->label );
354  }
355  return classes;
356 }
357 
359 {
361 
362  QRegularExpression linePartRx( QStringLiteral( "[\\s,:]+" ) );
363 
364  QStringList parts = string.split( '\n', QString::SkipEmptyParts );
365  const auto constParts = parts;
366  for ( const QString &part : constParts )
367  {
368  QStringList lineParts = part.split( linePartRx, QString::SkipEmptyParts );
369  bool ok = false;
370  switch ( lineParts.count() )
371  {
372  case 1:
373  {
374  int value = lineParts.at( 0 ).toInt( &ok );
375  if ( !ok )
376  continue;
377 
378  classes << Class( value );
379  break;
380  }
381 
382  case 2:
383  {
384  int value = lineParts.at( 0 ).toInt( &ok );
385  if ( !ok )
386  continue;
387 
388  QColor c( lineParts.at( 1 ) );
389 
390  classes << Class( value, c );
391  break;
392  }
393 
394  default:
395  {
396  if ( lineParts.count() < 4 )
397  continue;
398 
399  int value = lineParts.at( 0 ).toInt( &ok );
400  if ( !ok )
401  continue;
402 
403  bool rOk = false;
404  double r = lineParts.at( 1 ).toDouble( &rOk );
405  bool gOk = false;
406  double g = lineParts.at( 2 ).toDouble( &gOk );
407  bool bOk = false;
408  double b = lineParts.at( 3 ).toDouble( &bOk );
409 
410  QColor c;
411  if ( rOk && gOk && bOk )
412  {
413  c = QColor( r, g, b );
414  }
415 
416  if ( lineParts.count() >= 5 )
417  {
418  double alpha = lineParts.at( 4 ).toDouble( &ok );
419  if ( ok )
420  c.setAlpha( alpha );
421  }
422 
423  QString label;
424  if ( lineParts.count() > 5 )
425  {
426  label = lineParts.mid( 5 ).join( ' ' );
427  }
428 
429  classes << Class( value, c, label );
430  break;
431  }
432  }
433 
434  }
435  return classes;
436 }
437 
439 {
440  QFile inputFile( path );
441  QString input;
442  if ( inputFile.open( QIODevice::ReadOnly ) )
443  {
444  QTextStream in( &inputFile );
445  input = in.readAll();
446  inputFile.close();
447  }
448  return classDataFromString( input );
449 }
450 
452 {
453  QStringList out;
454  // must be sorted
456  std::sort( cd.begin(), cd.end(), []( const Class & a, const Class & b ) -> bool
457  {
458  return a.value < b.value;
459  } );
460 
461  const auto constCd = cd;
462  for ( const Class &c : constCd )
463  {
464  out << QStringLiteral( "%1 %2 %3 %4 %5 %6" ).arg( c.value ).arg( c.color.red() )
465  .arg( c.color.green() ).arg( c.color.blue() ).arg( c.color.alpha() ).arg( c.label );
466  }
467  return out.join( '\n' );
468 }
469 
471 {
472  if ( !raster )
473  return ClassData();
474 
475  // get min and max value from raster
476  QgsRasterBandStats stats = raster->bandStatistics( bandNumber, QgsRasterBandStats::Min | QgsRasterBandStats::Max, QgsRectangle(), 0, feedback );
477  if ( feedback && feedback->isCanceled() )
478  return ClassData();
479 
480  double min = stats.minimumValue;
481  double max = stats.maximumValue;
482  // need count of every individual value
483  int bins = std::ceil( max - min ) + 1;
484  if ( bins <= 0 )
485  return ClassData();
486 
487  QgsRasterHistogram histogram = raster->histogram( bandNumber, bins, min, max, QgsRectangle(), 0, false, feedback );
488  if ( feedback && feedback->isCanceled() )
489  return ClassData();
490 
491  double interval = ( histogram.maximum - histogram.minimum + 1 ) / histogram.binCount;
492 
493  ClassData data;
494 
495  double currentValue = histogram.minimum;
496  double presentValues = 0;
497  for ( int idx = 0; idx < histogram.binCount; ++idx )
498  {
499  int count = histogram.histogramVector.at( idx );
500  if ( count > 0 )
501  {
502  data << Class( currentValue, QColor(), QString::number( currentValue ) );
503  presentValues++;
504  }
505  currentValue += interval;
506  }
507 
508  // assign colors from ramp
509  if ( ramp )
510  {
511  int i = 0;
512 
513  if ( QgsRandomColorRamp *randomRamp = dynamic_cast<QgsRandomColorRamp *>( ramp ) )
514  {
515  //ramp is a random colors ramp, so inform it of the total number of required colors
516  //this allows the ramp to pregenerate a set of visually distinctive colors
517  randomRamp->setTotalColorCount( data.count() );
518  }
519 
520  if ( presentValues > 1 )
521  presentValues -= 1; //avoid duplicate first color
522 
523  QgsPalettedRasterRenderer::ClassData::iterator cIt = data.begin();
524  for ( ; cIt != data.end(); ++cIt )
525  {
526  cIt->color = ramp->color( i / presentValues );
527  i++;
528  }
529  }
530  return data;
531 }
532 
533 void QgsPalettedRasterRenderer::updateArrays()
534 {
535  mColors.clear();
536  int i = 0;
537  ClassData::const_iterator it = mClassData.constBegin();
538  for ( ; it != mClassData.constEnd(); ++it )
539  {
540  mColors[it->value] = qPremultiply( it->color.rgba() );
541  i++;
542  }
543 }
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:358
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:31
QgsRasterHistogram::histogramVector
QgsRasterHistogram::HistogramVector histogramVector
Stores the histogram for a given layer.
Definition: qgsrasterhistogram.h:84
QgsPalettedRasterRenderer::sourceColorRamp
QgsColorRamp * sourceColorRamp() const
Gets the source color ramp.
Definition: qgspalettedrasterrenderer.cpp:341
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
QgsPalettedRasterRenderer::label
QString label(int idx) const
Returns optional category label.
Definition: qgspalettedrasterrenderer.cpp:99
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
QgsRasterBandStats
Definition: qgsrasterbandstats.h:34
QgsStyleColorRampEntity
Definition: qgsstyle.h:1166
qgssymbollayerutils.h
QgsPalettedRasterRenderer::clone
QgsPalettedRasterRenderer * clone() const override
Clone itself, create deep copy.
Definition: qgspalettedrasterrenderer.cpp:39
QgsStyleEntityVisitorInterface
Definition: qgsstyleentityvisitor.h:33
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:346
QgsRectangle
Definition: qgsrectangle.h:41
QgsStyleEntityVisitorInterface::StyleLeaf
Contains information relating to the style entity currently being visited.
Definition: qgsstyleentityvisitor.h:60
QgsPalettedRasterRenderer::legendSymbologyItems
void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const override
Gets symbology items if provided by renderer.
Definition: qgspalettedrasterrenderer.cpp:316
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:124
QgsRandomColorRamp
Totally random color ramp. Returns colors generated at random, but constrained to some hardcoded satu...
Definition: qgscolorramp.h:427
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:304
QgsPalettedRasterRenderer::setSourceColorRamp
void setSourceColorRamp(QgsColorRamp *ramp)
Set the source color ramp.
Definition: qgspalettedrasterrenderer.cpp:336
QgsRasterBandStats::maximumValue
double maximumValue
The maximum cell value in the raster band.
Definition: qgsrasterbandstats.h:99
QgsPalettedRasterRenderer::create
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
Definition: qgspalettedrasterrenderer.cpp:49
QgsPalettedRasterRenderer::usesBands
QList< int > usesBands() const override
Returns a list of band numbers used by the renderer.
Definition: qgspalettedrasterrenderer.cpp:326
QgsRasterHistogram::minimum
double minimum
The minimum histogram value.
Definition: qgsrasterhistogram.h:90
qgspalettedrasterrenderer.h
QgsRasterRenderer
Definition: qgsrasterrenderer.h:38
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:470
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:3110
QgsRasterRenderer::mRasterTransparency
QgsRasterTransparency * mRasterTransparency
Raster transparency per color or value. Overwrites global alpha value.
Definition: qgsrasterrenderer.h:166
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
QgsPalettedRasterRenderer::band
int band() const
Returns the raster band used for rendering the raster.
Definition: qgspalettedrasterrenderer.h:98
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
QgsPalettedRasterRenderer::Class
Properties of a single value class.
Definition: qgspalettedrasterrenderer.h:40
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:66
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:251
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:451
QgsRasterHistogram::binCount
int binCount
Number of bins (intervals,buckets) in histogram.
Definition: qgsrasterhistogram.h:73
QgsPalettedRasterRenderer
Definition: qgspalettedrasterrenderer.h:35
qgsrastertransparency.h
QgsRasterRenderer::mAlphaBand
int mAlphaBand
Read alpha value from band.
Definition: qgsrasterrenderer.h:171
QgsPalettedRasterRenderer::QgsPalettedRasterRenderer
QgsPalettedRasterRenderer(QgsRasterInterface *input, int bandNumber, const ClassData &classes)
Constructor for QgsPalettedRasterRenderer.
Definition: qgspalettedrasterrenderer.cpp:31
QgsSymbolLayerUtils::loadColorRamp
static QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
Definition: qgssymbollayerutils.cpp:3085
QgsRasterBandStats::minimumValue
double minimumValue
The minimum cell value in the raster band.
Definition: qgsrasterbandstats.h:104
QgsFeedback::isCanceled
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:66
QgsRasterBandStats::Max
@ Max
Definition: qgsrasterbandstats.h:67
QgsPalettedRasterRenderer::writeXml
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
Definition: qgspalettedrasterrenderer.cpp:213
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:714
Qgis::ARGB32_Premultiplied
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
Definition: qgis.h:129
QgsRasterInterface
Definition: qgsrasterinterface.h:116
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:403
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
Definition: qgsrasterhistogram.h:33
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
Definition: qgsrasterinterface.h:40
QgsColorRamp::color
virtual QColor color(double value) const =0
Returns the color corresponding to a specified value.
QgsRasterRenderer::mOpacity
double mOpacity
Global alpha value (0-1)
Definition: qgsrasterrenderer.h:164
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:94
QgsPalettedRasterRenderer::setLabel
void setLabel(int idx, const QString &label)
Set category label.
Definition: qgspalettedrasterrenderer.cpp:111
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:87
QgsPalettedRasterRenderer::classDataFromFile
static QgsPalettedRasterRenderer::ClassData classDataFromFile(const QString &path)
Opens a color table file and returns corresponding paletted renderer class data.
Definition: qgspalettedrasterrenderer.cpp:438
QgsRasterBlock
Definition: qgsrasterblock.h:36
QgsRasterInterface::extent
virtual QgsRectangle extent() const
Gets the extent of the interface.
Definition: qgsrasterinterface.h:229
qgsstyleentityvisitor.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:723