62 theStatistics.
extent = myExtent;
64 if ( theSampleSize > 0 )
68 xRes = yRes = sqrt(( myExtent.
width() * myExtent.
height() ) / theSampleSize );
75 if ( xRes < srcXRes ) xRes = srcXRes;
76 if ( yRes < srcYRes ) yRes = srcYRes;
80 theStatistics.
width = static_cast <
int>( myExtent.
width() / xRes );
81 theStatistics.
height = static_cast <
int>( myExtent.
height() / yRes );
92 theStatistics.
width = 1000;
93 theStatistics.
height = 1000;
104 QgsDebugMsgLevel(
QString(
"theBandNo = %1 theStats = %2 theSampleSize = %3" ).arg( theBandNo ).arg( theStats ).arg( theSampleSize ), 4 );
108 initStatistics( myRasterBandStats, theBandNo, theStats, theExtent, theSampleSize );
112 if ( stats.
contains( myRasterBandStats ) )
126 QgsDebugMsgLevel(
QString(
"theBandNo = %1 theStats = %2 theSampleSize = %3" ).arg( theBandNo ).arg( theStats ).arg( theSampleSize ), 4 );
131 initStatistics( myRasterBandStats, theBandNo, theStats, theExtent, theSampleSize );
135 if ( stats.
contains( myRasterBandStats ) )
143 int myWidth = myRasterBandStats.
width;
144 int myHeight = myRasterBandStats.
height;
150 if ( myXBlockSize == 0 )
154 if ( myYBlockSize == 0 )
159 int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
160 int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;
162 double myXRes = myExtent.
width() / myWidth;
163 double myYRes = myExtent.
height() / myHeight;
168 double mySumOfSquares = 0;
170 bool myFirstIterationFlag =
true;
171 for (
int myYBlock = 0; myYBlock < myNYBlocks; myYBlock++ )
173 for (
int myXBlock = 0; myXBlock < myNXBlocks; myXBlock++ )
176 int myBlockWidth = qMin( myXBlockSize, myWidth - myXBlock * myXBlockSize );
177 int myBlockHeight = qMin( myYBlockSize, myHeight - myYBlock * myYBlockSize );
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;
189 for (
qgssize i = 0; i < ( static_cast< qgssize >( myBlockHeight ) ) * myBlockWidth; i++ )
193 double myValue = blk->
value( i );
195 myRasterBandStats.
sum += myValue;
198 if ( myFirstIterationFlag )
200 myFirstIterationFlag =
false;
217 double myDelta = myValue - myMean;
219 mySumOfSquares += myDelta * ( myValue - myMean );
233 myRasterBandStats.
stdDev = sqrt( mySumOfSquares / ( myRasterBandStats.
elementCount - 1 ) );
245 return myRasterBandStats;
251 double theMinimum,
double theMaximum,
254 bool theIncludeOutOfRange )
257 theHistogram.
minimum = theMinimum;
258 theHistogram.
maximum = theMaximum;
263 if ( qIsNaN( theHistogram.
minimum ) )
280 if ( qIsNaN( theHistogram.
maximum ) )
302 theHistogram.
extent = myExtent;
304 if ( theSampleSize > 0 )
308 xRes = yRes = sqrt(( myExtent.
width() * myExtent.
height() ) / theSampleSize );
315 if ( xRes < srcXRes ) xRes = srcXRes;
316 if ( yRes < srcYRes ) yRes = srcYRes;
320 theHistogram.
width = static_cast <
int>( myExtent.
width() / xRes );
321 theHistogram.
height = static_cast <
int>( myExtent.
height() / yRes );
332 theHistogram.
width = 1000;
333 theHistogram.
height = 1000;
338 int myBinCount = theBinCount;
339 if ( myBinCount == 0 )
350 myBinCount = theHistogram.
width * theHistogram.
height;
351 if ( myBinCount > 1000 ) myBinCount = 1000;
359 if ( myBinCount > theHistogram.
maximum - theHistogram.
minimum + 1 )
360 myBinCount = int( ceil( theHistogram.
maximum - theHistogram.
minimum + 1 ) );
371 double theMinimum,
double theMaximum,
374 bool theIncludeOutOfRange )
376 QgsDebugMsgLevel(
QString(
"theBandNo = %1 theBinCount = %2 theMinimum = %3 theMaximum = %4 theSampleSize = %5" ).arg( theBandNo ).arg( theBinCount ).arg( theMinimum ).arg( theMaximum ).arg( theSampleSize ), 4 );
382 initHistogram( myHistogram, theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );
386 if ( histogram == myHistogram )
397 double theMinimum,
double theMaximum,
400 bool theIncludeOutOfRange )
402 QgsDebugMsgLevel(
QString(
"theBandNo = %1 theBinCount = %2 theMinimum = %3 theMaximum = %4 theSampleSize = %5" ).arg( theBandNo ).arg( theBinCount ).arg( theMinimum ).arg( theMaximum ).arg( theSampleSize ), 4 );
405 initHistogram( myHistogram, theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );
410 if ( histogram == myHistogram )
417 int myBinCount = myHistogram.
binCount;
418 int myWidth = myHistogram.
width;
419 int myHeight = myHistogram.
height;
425 if ( myXBlockSize == 0 )
429 if ( myYBlockSize == 0 )
434 int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
435 int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;
437 double myXRes = myExtent.
width() / myWidth;
438 double myYRes = myExtent.
height() / myHeight;
440 double myMinimum = myHistogram.
minimum;
441 double myMaximum = myHistogram.
maximum;
445 double myerval = ( myMaximum - myMinimum ) / myHistogram.
binCount;
446 myMinimum -= 0.1 * myerval;
447 myMaximum += 0.1 * myerval;
451 double myBinSize = ( myMaximum - myMinimum ) / myBinCount;
454 for (
int myYBlock = 0; myYBlock < myNYBlocks; myYBlock++ )
456 for (
int myXBlock = 0; myXBlock < myNXBlocks; myXBlock++ )
458 int myBlockWidth = qMin( myXBlockSize, myWidth - myXBlock * myXBlockSize );
459 int myBlockHeight = qMin( myYBlockSize, myHeight - myYBlock * myYBlockSize );
461 double xmin = myExtent.
xMinimum() + myXBlock * myXBlockSize * myXRes;
462 double xmax = xmin + myBlockWidth * myXRes;
463 double ymin = myExtent.
yMaximum() - myYBlock * myYBlockSize * myYRes;
464 double ymax = ymin - myBlockHeight * myYRes;
471 for (
qgssize i = 0; i < ( static_cast< qgssize >( myBlockHeight ) ) * myBlockWidth; i++ )
477 double myValue = blk->
value( i );
479 int myBinIndex = static_cast <
int>( qFloor(( myValue - myMinimum ) / myBinSize ) );
481 if (( myBinIndex < 0 || myBinIndex > ( myBinCount - 1 ) ) && !theIncludeOutOfRange )
485 if ( myBinIndex < 0 ) myBinIndex = 0;
486 if ( myBinIndex > ( myBinCount - 1 ) ) myBinIndex = myBinCount - 1;
495 myHistogram.
valid =
true;
511 double theLowerCount,
double theUpperCount,
512 double &theLowerValue,
double &theUpperValue,
516 QgsDebugMsgLevel(
QString(
"theBandNo = %1 theLowerCount = %2 theUpperCount = %3 theSampleSize = %4" ).arg( theBandNo ).arg( theLowerCount ).arg( theUpperCount ).arg( theSampleSize ), 4 );
521 theLowerValue = std::numeric_limits<double>::quiet_NaN();
522 theUpperValue = std::numeric_limits<double>::quiet_NaN();
536 int myMinCount = static_cast< int >( qRound( theLowerCount * myHistogram.
nonNullCount ) );
537 int myMaxCount =
static_cast< int >( qRound( theUpperCount * myHistogram.
nonNullCount ) );
538 bool myLowerFound =
false;
545 myCount += myBinValue;
546 if ( !myLowerFound && myCount > myMinCount )
548 theLowerValue = myHistogram.
minimum + myBin * myBinXStep;
552 if ( myCount >= myMaxCount )
554 theUpperValue = myHistogram.
minimum + myBin * myBinXStep;
565 if ( theLowerValue != std::numeric_limits<double>::quiet_NaN() )
566 theLowerValue = floor( theLowerValue );
567 if ( theUpperValue != std::numeric_limits<double>::quiet_NaN() )
568 theUpperValue = ceil( theUpperValue );
584 abilitiesList += tr(
"Identify" );
589 abilitiesList += tr(
"Create Datasources" );
594 abilitiesList += tr(
"Remove Datasources" );
599 abilitiesList += tr(
"Build Pyramids" );
604 return abilitiesList.
join(
", " );
virtual ~QgsRasterInterface()
Eight bit unsigned integer (quint8)
A rectangle specified with double values.
double sum
The sum of all cells in the band.
void initHistogram(QgsRasterHistogram &theHistogram, int theBandNo, int theBinCount=0, double theMinimum=std::numeric_limits< double >::quiet_NaN(), double theMaximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0, bool theIncludeOutOfRange=false)
Fill in histogram defaults if not specified.
int bandNumber
The gdal band number (starts at 1)
int width
Number of columns used to calc histogram.
int height
Number of rows used to calc statistics.
int bandNumber
The gdal band number (starts at 1)
double minimum
The minimum histogram value.
double maximumValue
The maximum cell value in the raster band.
virtual int ySize() const
QgsRectangle intersect(const QgsRectangle *rect) const
return the intersection with the given rectangle
QString join(const QString &separator) const
int height
Number of rows used to calc histogram.
bool isNoData(int row, int column)
Check if value at position is no data.
bool contains(const QgsRasterBandStats &s) const
Compares region, size etc.
void initStatistics(QgsRasterBandStats &theStatistics, int theBandNo, int theStats=QgsRasterBandStats::All, const QgsRectangle &theExtent=QgsRectangle(), int theBinCount=0)
Fill in statistics defaults if not specified.
virtual int xBlockSize() const
Get block size.
QgsRectangle extent
Extent used to calc statistics.
virtual QgsRasterBandStats bandStatistics(int theBandNo, int theStats=QgsRasterBandStats::All, const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0)
Get band statistics.
double stdDev
The standard deviation of the cell values.
QString number(int n, int base)
The RasterBandStats struct is a container for statistics about a single raster band.
double mean
The mean cell value for the band.
virtual bool hasHistogram(int theBandNo, int theBinCount, double theMinimum=std::numeric_limits< double >::quiet_NaN(), double theMaximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0, bool theIncludeOutOfRange=false)
Returns true if histogram is available (cached, already calculated), the parameters are the same as i...
void append(const T &value)
Sixteen bit unsigned integer (quint16)
QgsRasterInterface(QgsRasterInterface *input=nullptr)
#define QgsDebugMsgLevel(str, level)
bool isEmpty() const
test if rectangle is empty.
Thirty two bit signed integer (qint32)
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
double width() const
Width of the rectangle.
QList< QgsRasterHistogram > mHistograms
List of cached histograms, all bands mixed.
qgssize elementCount
The number of not no data cells in the band.
Thirty two bit unsigned integer (quint32)
int statsGathered
Collected statistics.
QString capabilitiesString() const
Returns the above in friendly format.
virtual QGis::DataType srcDataType(int bandNo) const
Returns source data type for the band specified by number, source data type may be shorter than dataT...
Base class for processing filters like renderers, reprojector, resampler etc.
Sixteen bit signed integer (qint16)
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...
virtual QgsRasterHistogram histogram(int theBandNo, int theBinCount=0, double theMinimum=std::numeric_limits< double >::quiet_NaN(), double theMaximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0, bool theIncludeOutOfRange=false)
Get histogram.
double maximum
The maximum histogram value.
virtual QgsRectangle extent()
Get the extent of the interface.
virtual bool hasStatistics(int theBandNo, int theStats=QgsRasterBandStats::All, const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0)
Returns true if histogram is available (cached, already calculated).
virtual int yBlockSize() const
double range
The range is the distance between min & max.
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
double value(int row, int column) const
Read a single value if type of block is numeric.
double xMinimum() const
Get the x minimum value (left side of rectangle)
double minimumValue
The minimum cell value in the raster band.
The QgsRasterHistogram is a container for histogram of a single raster band.
int binCount
Number of bins (intervals,buckets) in histogram.
double yMaximum() const
Get the y maximum value (top side of rectangle)
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
HistogramVector histogramVector
Store the histogram for a given layer.
bool valid
Histogram is valid.
virtual void cumulativeCut(int theBandNo, double theLowerCount, double theUpperCount, double &theLowerValue, double &theUpperValue, const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0)
Find values for cumulative pixel count cut.
QgsRasterInterface * mInput
QgsRectangle extent
Extent used to calc histogram.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
virtual int xSize() const
Get raster size.
bool includeOutOfRange
Whether histogram includes out of range values (in first and last bin)
double height() const
Height of the rectangle.
double sumOfSquares
The sum of the squares.
int width
Number of columns used to calc statistics.
int nonNullCount
The number of non NULL cells used to calculate histogram.