QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsrasterinterface.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterface.cpp - Internal raster processing modules interface
3  --------------------------------------
4  Date : Jun 21, 2012
5  Copyright : (C) 2012 by Radim Blazek
6  email : radim dot blazek at gmail dot com
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 
18 #include <limits>
19 #include <typeinfo>
20 
21 #include <QByteArray>
22 #include <QTime>
23 #include <QStringList>
24 
25 #include "qgslogger.h"
26 #include "qgsrasterbandstats.h"
27 #include "qgsrasterhistogram.h"
28 #include "qgsrasterinterface.h"
29 #include "qgsrectangle.h"
30 
32  : mInput( input )
33 {
34 }
35 
37  int bandNo,
38  int stats,
39  const QgsRectangle &boundingBox,
40  int sampleSize )
41 {
42  QgsDebugMsgLevel( QStringLiteral( "theBandNo = %1 sampleSize = %2" ).arg( bandNo ).arg( sampleSize ), 4 );
43 
44  statistics.bandNumber = bandNo;
45  statistics.statsGathered = stats;
46 
47  QgsRectangle finalExtent;
48  if ( boundingBox.isEmpty() )
49  {
50  finalExtent = extent();
51  }
52  else
53  {
54  finalExtent = extent().intersect( boundingBox );
55  }
56  statistics.extent = finalExtent;
57 
58  if ( sampleSize > 0 )
59  {
60  // Calc resolution from theSampleSize
61  double xRes, yRes;
62  xRes = yRes = std::sqrt( ( finalExtent.width() * finalExtent.height() ) / sampleSize );
63 
64  // But limit by physical resolution
65  if ( capabilities() & Size )
66  {
67  double srcXRes = extent().width() / xSize();
68  double srcYRes = extent().height() / ySize();
69  if ( xRes < srcXRes ) xRes = srcXRes;
70  if ( yRes < srcYRes ) yRes = srcYRes;
71  }
72  QgsDebugMsgLevel( QStringLiteral( "xRes = %1 yRes = %2" ).arg( xRes ).arg( yRes ), 4 );
73 
74  statistics.width = static_cast <int>( std::ceil( finalExtent.width() / xRes ) );
75  statistics.height = static_cast <int>( std::ceil( finalExtent.height() / yRes ) );
76  }
77  else
78  {
79  if ( capabilities() & Size )
80  {
81  statistics.width = xSize();
82  statistics.height = ySize();
83  }
84  else
85  {
86  statistics.width = 1000;
87  statistics.height = 1000;
88  }
89  }
90  QgsDebugMsgLevel( QStringLiteral( "theStatistics.width = %1 statistics.height = %2" ).arg( statistics.width ).arg( statistics.height ), 4 );
91 }
92 
94  int stats,
95  const QgsRectangle &extent,
96  int sampleSize )
97 {
98  QgsDebugMsgLevel( QStringLiteral( "theBandNo = %1 stats = %2 sampleSize = %3" ).arg( bandNo ).arg( stats ).arg( sampleSize ), 4 );
99  if ( mStatistics.isEmpty() ) return false;
100 
101  QgsRasterBandStats myRasterBandStats;
102  initStatistics( myRasterBandStats, bandNo, stats, extent, sampleSize );
103 
104  const auto constMStatistics = mStatistics;
105  for ( const QgsRasterBandStats &stats : constMStatistics )
106  {
107  if ( stats.contains( myRasterBandStats ) )
108  {
109  QgsDebugMsgLevel( QStringLiteral( "Has cached statistics." ), 4 );
110  return true;
111  }
112  }
113  return false;
114 }
115 
117  int stats,
118  const QgsRectangle &extent,
119  int sampleSize, QgsRasterBlockFeedback *feedback )
120 {
121  QgsDebugMsgLevel( QStringLiteral( "theBandNo = %1 stats = %2 sampleSize = %3" ).arg( bandNo ).arg( stats ).arg( sampleSize ), 4 );
122 
123  // TODO: null values set on raster layer!!!
124 
125  QgsRasterBandStats myRasterBandStats;
126  initStatistics( myRasterBandStats, bandNo, stats, extent, sampleSize );
127 
128  const auto constMStatistics = mStatistics;
129  for ( const QgsRasterBandStats &stats : constMStatistics )
130  {
131  if ( stats.contains( myRasterBandStats ) )
132  {
133  QgsDebugMsgLevel( QStringLiteral( "Using cached statistics." ), 4 );
134  return stats;
135  }
136  }
137 
138  QgsRectangle myExtent = myRasterBandStats.extent;
139  int myWidth = myRasterBandStats.width;
140  int myHeight = myRasterBandStats.height;
141 
142  //int myDataType = dataType( bandNo );
143 
144  int myXBlockSize = xBlockSize();
145  int myYBlockSize = yBlockSize();
146  if ( myXBlockSize == 0 ) // should not happen, but happens
147  {
148  myXBlockSize = 500;
149  }
150  if ( myYBlockSize == 0 ) // should not happen, but happens
151  {
152  myYBlockSize = 500;
153  }
154 
155  int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
156  int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;
157 
158  double myXRes = myExtent.width() / myWidth;
159  double myYRes = myExtent.height() / myHeight;
160  // TODO: progress signals
161 
162  // used by single pass stdev
163  double myMean = 0;
164  double mySumOfSquares = 0;
165 
166  bool myFirstIterationFlag = true;
167  bool isNoData = false;
168  for ( int myYBlock = 0; myYBlock < myNYBlocks; myYBlock++ )
169  {
170  for ( int myXBlock = 0; myXBlock < myNXBlocks; myXBlock++ )
171  {
172  if ( feedback && feedback->isCanceled() )
173  return myRasterBandStats;
174 
175  QgsDebugMsgLevel( QStringLiteral( "myYBlock = %1 myXBlock = %2" ).arg( myYBlock ).arg( myXBlock ), 4 );
176  int myBlockWidth = std::min( myXBlockSize, myWidth - myXBlock * myXBlockSize );
177  int myBlockHeight = std::min( myYBlockSize, myHeight - myYBlock * myYBlockSize );
178 
179  double xmin = myExtent.xMinimum() + myXBlock * myXBlockSize * myXRes;
180  double xmax = xmin + myBlockWidth * myXRes;
181  double ymin = myExtent.yMaximum() - myYBlock * myYBlockSize * myYRes;
182  double ymax = ymin - myBlockHeight * myYRes;
183 
184  QgsRectangle myPartExtent( xmin, ymin, xmax, ymax );
185 
186  std::unique_ptr< QgsRasterBlock > blk( block( bandNo, myPartExtent, myBlockWidth, myBlockHeight, feedback ) );
187 
188  // Collect the histogram counts.
189  for ( qgssize i = 0; i < ( static_cast< qgssize >( myBlockHeight ) ) * myBlockWidth; i++ )
190  {
191  double myValue = blk->valueAndNoData( i, isNoData );
192  if ( isNoData )
193  continue; // NULL
194 
195  myRasterBandStats.sum += myValue;
196  myRasterBandStats.elementCount++;
197 
198  if ( !std::isfinite( myValue ) ) continue; // inf
199 
200  if ( myFirstIterationFlag )
201  {
202  myFirstIterationFlag = false;
203  myRasterBandStats.minimumValue = myValue;
204  myRasterBandStats.maximumValue = myValue;
205  }
206  else
207  {
208  if ( myValue < myRasterBandStats.minimumValue )
209  {
210  myRasterBandStats.minimumValue = myValue;
211  }
212  if ( myValue > myRasterBandStats.maximumValue )
213  {
214  myRasterBandStats.maximumValue = myValue;
215  }
216  }
217 
218  // Single pass stdev
219  double myDelta = myValue - myMean;
220  myMean += myDelta / myRasterBandStats.elementCount;
221  mySumOfSquares += myDelta * ( myValue - myMean );
222  }
223  }
224  }
225 
226  myRasterBandStats.range = myRasterBandStats.maximumValue - myRasterBandStats.minimumValue;
227  myRasterBandStats.mean = myRasterBandStats.sum / myRasterBandStats.elementCount;
228 
229  myRasterBandStats.sumOfSquares = mySumOfSquares; // OK with single pass?
230 
231  // stdDev may differ from GDAL stats, because GDAL is using naive single pass
232  // algorithm which is more error prone (because of rounding errors)
233  // Divide result by sample size - 1 and get square root to get stdev
234  myRasterBandStats.stdDev = std::sqrt( mySumOfSquares / ( myRasterBandStats.elementCount - 1 ) );
235 
236  QgsDebugMsgLevel( QStringLiteral( "************ STATS **************" ), 4 );
237  QgsDebugMsgLevel( QStringLiteral( "MIN %1" ).arg( myRasterBandStats.minimumValue ), 4 );
238  QgsDebugMsgLevel( QStringLiteral( "MAX %1" ).arg( myRasterBandStats.maximumValue ), 4 );
239  QgsDebugMsgLevel( QStringLiteral( "RANGE %1" ).arg( myRasterBandStats.range ), 4 );
240  QgsDebugMsgLevel( QStringLiteral( "MEAN %1" ).arg( myRasterBandStats.mean ), 4 );
241  QgsDebugMsgLevel( QStringLiteral( "STDDEV %1" ).arg( myRasterBandStats.stdDev ), 4 );
242 
243  myRasterBandStats.statsGathered = QgsRasterBandStats::All;
244  mStatistics.append( myRasterBandStats );
245 
246  return myRasterBandStats;
247 }
248 
250  int bandNo,
251  int binCount,
252  double minimum, double maximum,
253  const QgsRectangle &boundingBox,
254  int sampleSize,
255  bool includeOutOfRange )
256 {
257  histogram.bandNumber = bandNo;
258  histogram.minimum = minimum;
259  histogram.maximum = maximum;
260  histogram.includeOutOfRange = includeOutOfRange;
261 
262  int mySrcDataType = sourceDataType( bandNo );
263 
264  if ( std::isnan( histogram.minimum ) )
265  {
266  // TODO: this was OK when stats/histogram were calced in provider,
267  // but what TODO in other interfaces? Check for mInput for now.
268  if ( !mInput && mySrcDataType == Qgis::Byte )
269  {
270  histogram.minimum = 0; // see histogram() for shift for rounding
271  }
272  else
273  {
274  // We need statistics -> avoid histogramDefaults in hasHistogram if possible
275  // TODO: use approximated statistics if approximated histogram is requested
276  // (theSampleSize > 0)
277  QgsRasterBandStats stats = bandStatistics( bandNo, QgsRasterBandStats::Min, boundingBox, sampleSize );
279  }
280  }
281  if ( std::isnan( histogram.maximum ) )
282  {
283  if ( !mInput && mySrcDataType == Qgis::Byte )
284  {
285  histogram.maximum = 255;
286  }
287  else
288  {
289  QgsRasterBandStats stats = bandStatistics( bandNo, QgsRasterBandStats::Max, boundingBox, sampleSize );
291  }
292  }
293 
294  QgsRectangle finalExtent;
295  if ( boundingBox.isEmpty() )
296  {
297  finalExtent = extent();
298  }
299  else
300  {
301  finalExtent = extent().intersect( boundingBox );
302  }
303  histogram.extent = finalExtent;
304 
305  if ( sampleSize > 0 )
306  {
307  // Calc resolution from theSampleSize
308  double xRes, yRes;
309  xRes = yRes = std::sqrt( ( finalExtent.width() * finalExtent.height() ) / sampleSize );
310 
311  // But limit by physical resolution
312  if ( capabilities() & Size )
313  {
314  double srcXRes = extent().width() / xSize();
315  double srcYRes = extent().height() / ySize();
316  if ( xRes < srcXRes ) xRes = srcXRes;
317  if ( yRes < srcYRes ) yRes = srcYRes;
318  }
319  QgsDebugMsgLevel( QStringLiteral( "xRes = %1 yRes = %2" ).arg( xRes ).arg( yRes ), 4 );
320 
321  histogram.width = static_cast <int>( finalExtent.width() / xRes );
322  histogram.height = static_cast <int>( finalExtent.height() / yRes );
323  }
324  else
325  {
326  if ( capabilities() & Size )
327  {
328  histogram.width = xSize();
329  histogram.height = ySize();
330  }
331  else
332  {
333  histogram.width = 1000;
334  histogram.height = 1000;
335  }
336  }
337  QgsDebugMsgLevel( QStringLiteral( "theHistogram.width = %1 histogram.height = %2" ).arg( histogram.width ).arg( histogram.height ), 4 );
338 
339  int myBinCount = binCount;
340  if ( myBinCount == 0 )
341  {
342  // TODO: this was OK when stats/histogram were calced in provider,
343  // but what TODO in other interfaces? Check for mInput for now.
344  if ( !mInput && mySrcDataType == Qgis::Byte )
345  {
346  myBinCount = 256; // Cannot store more values in byte
347  }
348  else
349  {
350  // There is no best default value, to display something reasonable in histogram chart,
351  // binCount should be small, OTOH, to get precise data for cumulative cut, the number should be big.
352  // Because it is easier to define fixed lower value for the chart, we calc optimum binCount
353  // for higher resolution (to avoid calculating that where histogram() is used. In any any case,
354  // it does not make sense to use more than width*height;
355 
356  // for Int16/Int32 make sure bin count <= actual range, because there is no sense in having
357  // bins at fractional values
358  if ( !mInput && (
359  mySrcDataType == Qgis::Int16 || mySrcDataType == Qgis::Int32 ||
360  mySrcDataType == Qgis::UInt16 || mySrcDataType == Qgis::UInt32 ) )
361  {
362  myBinCount = std::min( histogram.width * histogram.height, static_cast<int>( std::ceil( histogram.maximum - histogram.minimum + 1 ) ) );
363  }
364  else
365  {
366  // This is for not integer types:
367  myBinCount = std::min( 2000, histogram.width * histogram.height );
368  }
369  }
370  }
371  histogram.binCount = myBinCount;
372  QgsDebugMsgLevel( QStringLiteral( "theHistogram.binCount = %1" ).arg( histogram.binCount ), 4 );
373 }
374 
375 
377  int binCount,
378  double minimum, double maximum,
379  const QgsRectangle &extent,
380  int sampleSize,
381  bool includeOutOfRange )
382 {
383  QgsDebugMsgLevel( QStringLiteral( "theBandNo = %1 binCount = %2 minimum = %3 maximum = %4 sampleSize = %5" ).arg( bandNo ).arg( binCount ).arg( minimum ).arg( maximum ).arg( sampleSize ), 4 );
384  // histogramDefaults() needs statistics if minimum or maximum is NaN ->
385  // do other checks which don't need statistics before histogramDefaults()
386  if ( mHistograms.isEmpty() ) return false;
387 
388  QgsRasterHistogram myHistogram;
389  initHistogram( myHistogram, bandNo, binCount, minimum, maximum, extent, sampleSize, includeOutOfRange );
390 
391  const auto constMHistograms = mHistograms;
392  for ( const QgsRasterHistogram &histogram : constMHistograms )
393  {
394  if ( histogram == myHistogram )
395  {
396  QgsDebugMsgLevel( QStringLiteral( "Has cached histogram." ), 4 );
397  return true;
398  }
399  }
400  return false;
401 }
402 
404  int binCount,
405  double minimum, double maximum,
406  const QgsRectangle &extent,
407  int sampleSize,
408  bool includeOutOfRange, QgsRasterBlockFeedback *feedback )
409 {
410  QgsDebugMsgLevel( QStringLiteral( "theBandNo = %1 binCount = %2 minimum = %3 maximum = %4 sampleSize = %5" ).arg( bandNo ).arg( binCount ).arg( minimum ).arg( maximum ).arg( sampleSize ), 4 );
411 
412  QgsRasterHistogram myHistogram;
413  initHistogram( myHistogram, bandNo, binCount, minimum, maximum, extent, sampleSize, includeOutOfRange );
414 
415  // Find cached
416  const auto constMHistograms = mHistograms;
417  for ( const QgsRasterHistogram &histogram : constMHistograms )
418  {
419  if ( histogram == myHistogram )
420  {
421  QgsDebugMsgLevel( QStringLiteral( "Using cached histogram." ), 4 );
422  return histogram;
423  }
424  }
425 
426  int myBinCount = myHistogram.binCount;
427  int myWidth = myHistogram.width;
428  int myHeight = myHistogram.height;
429  QgsRectangle myExtent = myHistogram.extent;
430  myHistogram.histogramVector.resize( myBinCount );
431 
432  int myXBlockSize = xBlockSize();
433  int myYBlockSize = yBlockSize();
434  if ( myXBlockSize == 0 ) // should not happen, but happens
435  {
436  myXBlockSize = 500;
437  }
438  if ( myYBlockSize == 0 ) // should not happen, but happens
439  {
440  myYBlockSize = 500;
441  }
442 
443  int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
444  int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;
445 
446  double myXRes = myExtent.width() / myWidth;
447  double myYRes = myExtent.height() / myHeight;
448 
449  double myMinimum = myHistogram.minimum;
450  double myMaximum = myHistogram.maximum;
451 
452  // To avoid rounding errors
453  // TODO: check this
454  double myerval = ( myMaximum - myMinimum ) / myHistogram.binCount;
455  myMinimum -= 0.1 * myerval;
456  myMaximum += 0.1 * myerval;
457 
458  QgsDebugMsgLevel( QStringLiteral( "binCount = %1 myMinimum = %2 myMaximum = %3" ).arg( myHistogram.binCount ).arg( myMinimum ).arg( myMaximum ), 4 );
459 
460  double myBinSize = ( myMaximum - myMinimum ) / myBinCount;
461 
462  // TODO: progress signals
463  bool isNoData = false;
464  for ( int myYBlock = 0; myYBlock < myNYBlocks; myYBlock++ )
465  {
466  for ( int myXBlock = 0; myXBlock < myNXBlocks; myXBlock++ )
467  {
468  if ( feedback && feedback->isCanceled() )
469  return myHistogram;
470 
471  int myBlockWidth = std::min( myXBlockSize, myWidth - myXBlock * myXBlockSize );
472  int myBlockHeight = std::min( myYBlockSize, myHeight - myYBlock * myYBlockSize );
473 
474  double xmin = myExtent.xMinimum() + myXBlock * myXBlockSize * myXRes;
475  double xmax = xmin + myBlockWidth * myXRes;
476  double ymin = myExtent.yMaximum() - myYBlock * myYBlockSize * myYRes;
477  double ymax = ymin - myBlockHeight * myYRes;
478 
479  QgsRectangle myPartExtent( xmin, ymin, xmax, ymax );
480 
481  std::unique_ptr< QgsRasterBlock > blk( block( bandNo, myPartExtent, myBlockWidth, myBlockHeight, feedback ) );
482 
483  // Collect the histogram counts.
484  for ( qgssize i = 0; i < ( static_cast< qgssize >( myBlockHeight ) ) * myBlockWidth; i++ )
485  {
486  double myValue = blk->valueAndNoData( i, isNoData );
487  if ( isNoData )
488  {
489  continue; // NULL
490  }
491 
492  int myBinIndex = static_cast <int>( std::floor( ( myValue - myMinimum ) / myBinSize ) );
493 
494  if ( ( myBinIndex < 0 || myBinIndex > ( myBinCount - 1 ) ) && !includeOutOfRange )
495  {
496  continue;
497  }
498  if ( myBinIndex < 0 ) myBinIndex = 0;
499  if ( myBinIndex > ( myBinCount - 1 ) ) myBinIndex = myBinCount - 1;
500 
501  myHistogram.histogramVector[myBinIndex] += 1;
502  myHistogram.nonNullCount++;
503  }
504  }
505  }
506 
507  myHistogram.valid = true;
508  mHistograms.append( myHistogram );
509 
510 #ifdef QGISDEBUG
511  QString hist;
512  for ( int i = 0; i < std::min( myHistogram.histogramVector.size(), 500 ); i++ )
513  {
514  hist += QString::number( myHistogram.histogramVector.value( i ) ) + ' ';
515  }
516  QgsDebugMsgLevel( QStringLiteral( "Histogram (max first 500 bins): " ) + hist, 4 );
517 #endif
518 
519  return myHistogram;
520 }
521 
523  double lowerCount, double upperCount,
524  double &lowerValue, double &upperValue,
525  const QgsRectangle &extent,
526  int sampleSize )
527 {
528  QgsDebugMsgLevel( QStringLiteral( "theBandNo = %1 lowerCount = %2 upperCount = %3 sampleSize = %4" ).arg( bandNo ).arg( lowerCount ).arg( upperCount ).arg( sampleSize ), 4 );
529 
530  int mySrcDataType = sourceDataType( bandNo );
531 
532  // Init to NaN is better than histogram min/max to catch errors
533  lowerValue = std::numeric_limits<double>::quiet_NaN();
534  upperValue = std::numeric_limits<double>::quiet_NaN();
535 
536  //get band stats to specify real histogram min/max (fix #9793 Byte bands)
537  QgsRasterBandStats stats = bandStatistics( bandNo, QgsRasterBandStats::Min, extent, sampleSize );
538  if ( stats.maximumValue < stats.minimumValue )
539  return;
540 
541  // for byte bands make sure bin count == actual range
542  int myBinCount = ( mySrcDataType == Qgis::Byte ) ? int( std::ceil( stats.maximumValue - stats.minimumValue + 1 ) ) : 0;
543  QgsRasterHistogram myHistogram = histogram( bandNo, myBinCount, stats.minimumValue, stats.maximumValue, extent, sampleSize );
544  //QgsRasterHistogram myHistogram = histogram( bandNo, 0, std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), extent, sampleSize );
545 
546  double myBinXStep = ( myHistogram.maximum - myHistogram.minimum ) / myHistogram.binCount;
547  int myCount = 0;
548  int myMinCount = static_cast< int >( std::round( lowerCount * myHistogram.nonNullCount ) );
549  int myMaxCount = static_cast< int >( std::round( upperCount * myHistogram.nonNullCount ) );
550  bool myLowerFound = false;
551  QgsDebugMsgLevel( QStringLiteral( "binCount = %1 minimum = %2 maximum = %3 myBinXStep = %4" ).arg( myHistogram.binCount ).arg( myHistogram.minimum ).arg( myHistogram.maximum ).arg( myBinXStep ), 4 );
552  QgsDebugMsgLevel( QStringLiteral( "myMinCount = %1 myMaxCount = %2" ).arg( myMinCount ).arg( myMaxCount ), 4 );
553 
554  for ( int myBin = 0; myBin < myHistogram.histogramVector.size(); myBin++ )
555  {
556  int myBinValue = myHistogram.histogramVector.value( myBin );
557  myCount += myBinValue;
558  if ( !myLowerFound && myCount > myMinCount )
559  {
560  lowerValue = myHistogram.minimum + myBin * myBinXStep;
561  myLowerFound = true;
562  QgsDebugMsgLevel( QStringLiteral( "found lowerValue %1 at bin %2" ).arg( lowerValue ).arg( myBin ), 4 );
563  }
564  if ( myCount >= myMaxCount )
565  {
566  upperValue = myHistogram.minimum + myBin * myBinXStep;
567  QgsDebugMsgLevel( QStringLiteral( "found upperValue %1 at bin %2" ).arg( upperValue ).arg( myBin ), 4 );
568  break;
569  }
570  }
571 
572  // fix integer data - round down/up
573  if ( mySrcDataType == Qgis::Byte ||
574  mySrcDataType == Qgis::Int16 || mySrcDataType == Qgis::Int32 ||
575  mySrcDataType == Qgis::UInt16 || mySrcDataType == Qgis::UInt32 )
576  {
577  if ( !std::isnan( lowerValue ) )
578  lowerValue = std::floor( lowerValue );
579  if ( !std::isnan( upperValue ) )
580  upperValue = std::ceil( upperValue );
581  }
582 }
583 
585 {
586  QStringList abilitiesList;
587 
588  int abilities = capabilities();
589 
590  // Not all all capabilities are here (Size, IdentifyValue, IdentifyText,
591  // IdentifyHtml, IdentifyFeature) because those are quite technical and probably
592  // would be confusing for users
593 
594  if ( abilities & QgsRasterInterface::Identify )
595  {
596  abilitiesList += tr( "Identify" );
597  }
598 
599  if ( abilities & QgsRasterInterface::Create )
600  {
601  abilitiesList += tr( "Create Datasources" );
602  }
603 
604  if ( abilities & QgsRasterInterface::Remove )
605  {
606  abilitiesList += tr( "Remove Datasources" );
607  }
608 
609  if ( abilities & QgsRasterInterface::BuildPyramids )
610  {
611  abilitiesList += tr( "Build Pyramids" );
612  }
613 
614  QgsDebugMsgLevel( "Capability: " + abilitiesList.join( QStringLiteral( ", " ) ), 4 );
615 
616  return abilitiesList.join( QStringLiteral( ", " ) );
617 }
QgsRasterInterface::hasStatistics
virtual bool hasStatistics(int bandNo, int stats=QgsRasterBandStats::All, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0)
Returns true if histogram is available (cached, already calculated).
Definition: qgsrasterinterface.cpp:93
qgsrasterbandstats.h
QgsRasterHistogram::histogramVector
QgsRasterHistogram::HistogramVector histogramVector
Stores the histogram for a given layer.
Definition: qgsrasterhistogram.h:84
QgsRasterBandStats::elementCount
qgssize elementCount
The number of not no data cells in the band.
Definition: qgsrasterbandstats.h:94
Qgis::UInt32
@ UInt32
Thirty two bit unsigned integer (quint32)
Definition: qgis.h:120
QgsRasterInterface::mStatistics
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
Definition: qgsrasterinterface.h:470
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::sourceDataType
virtual Qgis::DataType sourceDataType(int bandNo) const
Returns source data type for the band specified by number, source data type may be shorter than dataT...
Definition: qgsrasterinterface.h:223
qgsrectangle.h
QgsRasterInterface::Size
@ Size
Definition: qgsrasterinterface.h:186
qgsrasterhistogram.h
QgsRasterInterface::mInput
QgsRasterInterface * mInput
Definition: qgsrasterinterface.h:467
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsRasterInterface::cumulativeCut
virtual void cumulativeCut(int bandNo, double lowerCount, double upperCount, double &lowerValue, double &upperValue, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0)
Find values for cumulative pixel count cut.
Definition: qgsrasterinterface.cpp:522
QgsRasterBandStats
Definition: qgsrasterbandstats.h:34
QgsRasterBandStats::sumOfSquares
double sumOfSquares
The sum of the squares. Used to calculate standard deviation.
Definition: qgsrasterbandstats.h:122
QgsRasterInterface::xBlockSize
virtual int xBlockSize() const
Gets block size.
Definition: qgsrasterinterface.h:237
QgsRasterBandStats::mean
double mean
The mean cell value for the band. NO_DATA values are excluded.
Definition: qgsrasterbandstats.h:107
QgsRasterInterface::BuildPyramids
@ BuildPyramids
Definition: qgsrasterinterface.h:189
QgsRasterInterface::initStatistics
void initStatistics(QgsRasterBandStats &statistics, int bandNo, int stats=QgsRasterBandStats::All, const QgsRectangle &boundingBox=QgsRectangle(), int binCount=0)
Fill in statistics defaults if not specified.
Definition: qgsrasterinterface.cpp:36
QgsRasterInterface::yBlockSize
virtual int yBlockSize() const
Definition: qgsrasterinterface.h:238
QgsRasterInterface::hasHistogram
virtual bool hasHistogram(int bandNo, int binCount, 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)
Returns true if histogram is available (cached, already calculated)
Definition: qgsrasterinterface.cpp:376
QgsRasterBandStats::range
double range
The range is the distance between min & max.
Definition: qgsrasterbandstats.h:110
QgsRasterHistogram::valid
bool valid
Histogram is valid.
Definition: qgsrasterhistogram.h:102
QgsRectangle::intersect
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
Definition: qgsrectangle.h:312
QgsRasterInterface::Identify
@ Identify
Definition: qgsrasterinterface.h:190
QgsRectangle
Definition: qgsrectangle.h:41
QgsRasterBandStats::maximumValue
double maximumValue
The maximum cell value in the raster band.
Definition: qgsrasterbandstats.h:99
QgsRasterHistogram::extent
QgsRectangle extent
Extent used to calc histogram.
Definition: qgsrasterhistogram.h:99
qgsrasterinterface.h
QgsRasterHistogram::includeOutOfRange
bool includeOutOfRange
Whether histogram includes out of range values (in first and last bin)
Definition: qgsrasterhistogram.h:79
QgsRasterHistogram::minimum
double minimum
The minimum histogram value.
Definition: qgsrasterhistogram.h:90
QgsRasterBandStats::All
@ All
Definition: qgsrasterbandstats.h:73
QgsRasterInterface::xSize
virtual int xSize() const
Gets raster size.
Definition: qgsrasterinterface.h:241
QgsRasterBandStats::Min
@ Min
Definition: qgsrasterbandstats.h:66
QgsRasterInterface::Create
@ Create
Definition: qgsrasterinterface.h:187
QgsRasterHistogram::binCount
int binCount
Number of bins (intervals,buckets) in histogram.
Definition: qgsrasterhistogram.h:73
QgsRasterHistogram::nonNullCount
int nonNullCount
The number of non NULL cells used to calculate histogram.
Definition: qgsrasterhistogram.h:76
Qgis::UInt16
@ UInt16
Sixteen bit unsigned integer (quint16)
Definition: qgis.h:118
QgsRasterInterface::initHistogram
void initHistogram(QgsRasterHistogram &histogram, int bandNo, int binCount, double minimum=std::numeric_limits< double >::quiet_NaN(), double maximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &boundingBox=QgsRectangle(), int sampleSize=0, bool includeOutOfRange=false)
Fill in histogram defaults if not specified.
Definition: qgsrasterinterface.cpp:249
QgsRectangle::yMaximum
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
QgsRasterInterface::ySize
virtual int ySize() const
Definition: qgsrasterinterface.h:242
QgsRasterInterface::Remove
@ Remove
Definition: qgsrasterinterface.h:188
QgsRasterBandStats::sum
double sum
The sum of all cells in the band. NO_DATA values are excluded.
Definition: qgsrasterbandstats.h:119
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
QgsRasterInterface::mHistograms
QList< QgsRasterHistogram > mHistograms
List of cached histograms, all bands mixed.
Definition: qgsrasterinterface.h:473
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
QgsRasterHistogram
Definition: qgsrasterhistogram.h:33
QgsRasterBlockFeedback
Definition: qgsrasterinterface.h:40
QgsRectangle::height
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
Qgis::Int16
@ Int16
Sixteen bit signed integer (qint16)
Definition: qgis.h:119
QgsRasterBandStats::extent
QgsRectangle extent
Extent used to calc statistics.
Definition: qgsrasterbandstats.h:131
QgsRasterBandStats::width
int width
Number of columns used to calc statistics.
Definition: qgsrasterbandstats.h:125
Qgis::Int32
@ Int32
Thirty two bit signed integer (qint32)
Definition: qgis.h:121
QgsRasterHistogram::height
int height
Number of rows used to calc histogram.
Definition: qgsrasterhistogram.h:96
QgsRasterBandStats::stdDev
double stdDev
The standard deviation of the cell values.
Definition: qgsrasterbandstats.h:113
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.
qgslogger.h
QgsRasterHistogram::width
int width
Number of columns used to calc histogram.
Definition: qgsrasterhistogram.h:93
QgsRasterHistogram::maximum
double maximum
The maximum histogram value.
Definition: qgsrasterhistogram.h:87
QgsRasterInterface::QgsRasterInterface
QgsRasterInterface(QgsRasterInterface *input=nullptr)
Definition: qgsrasterinterface.cpp:31
Qgis::Byte
@ Byte
Eight bit unsigned integer (quint8)
Definition: qgis.h:117
QgsRectangle::isEmpty
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:437
QgsRasterInterface::capabilities
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
Definition: qgsrasterinterface.h:206
QgsRasterBandStats::statsGathered
int statsGathered
Collected statistics.
Definition: qgsrasterbandstats.h:116
QgsRasterInterface::capabilitiesString
QString capabilitiesString() const
Returns the raster interface capabilities in friendly format.
Definition: qgsrasterinterface.cpp:584
QgsRectangle::width
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsRectangle::xMinimum
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
QgsRasterInterface::extent
virtual QgsRectangle extent() const
Gets the extent of the interface.
Definition: qgsrasterinterface.h:229
QgsRasterHistogram::bandNumber
int bandNumber
The gdal band number (starts at 1)
Definition: qgsrasterhistogram.h:70
QgsRasterBandStats::height
int height
Number of rows used to calc statistics.
Definition: qgsrasterbandstats.h:128
QgsRasterBandStats::bandNumber
int bandNumber
The gdal band number (starts at 1)
Definition: qgsrasterbandstats.h:90
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