48 QgsDebugMsg( QString(
"theBandNo = %1 theSampleSize = %2" ).arg( theBandNo ).arg( theSampleSize ) );
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;
78 QgsDebugMsg( QString(
"xRes = %1 yRes = %2" ).arg( xRes ).arg( yRes ) );
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;
96 QgsDebugMsg( QString(
"theStatistics.width = %1 theStatistics.height = %2" ).arg( theStatistics.
width ).arg( theStatistics.
height ) );
104 QgsDebugMsg( QString(
"theBandNo = %1 theStats = %2 theSampleSize = %3" ).arg( theBandNo ).arg( theStats ).arg( theSampleSize ) );
108 initStatistics( myRasterBandStats, theBandNo, theStats, theExtent, theSampleSize );
112 if ( stats.
contains( myRasterBandStats ) )
126 QgsDebugMsg( QString(
"theBandNo = %1 theStats = %2 theSampleSize = %3" ).arg( theBandNo ).arg( theStats ).arg( theSampleSize ) );
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++ )
175 QgsDebugMsg( QString(
"myYBlock = %1 myXBlock = %2" ).arg( myYBlock ).arg( 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 (
size_t i = 0; i < (( size_t ) 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 ) );
235 QgsDebugMsg(
"************ STATS **************" );
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;
318 QgsDebugMsg( QString(
"xRes = %1 yRes = %2" ).arg( xRes ).arg( yRes ) );
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;
336 QgsDebugMsg( QString(
"theHistogram.width = %1 theHistogram.height = %2" ).arg( theHistogram.
width ).arg( theHistogram.
height ) );
338 int myBinCount = theBinCount;
339 if ( myBinCount == 0 )
350 myBinCount = theHistogram.
width * theHistogram.
height;
351 if ( myBinCount > 1000 ) myBinCount = 1000;
361 double theMinimum,
double theMaximum,
364 bool theIncludeOutOfRange )
366 QgsDebugMsg( QString(
"theBandNo = %1 theBinCount = %2 theMinimum = %3 theMaximum = %4 theSampleSize = %5" ).arg( theBandNo ).arg( theBinCount ).arg( theMinimum ).arg( theMaximum ).arg( theSampleSize ) );
372 initHistogram( myHistogram, theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );
376 if ( histogram == myHistogram )
387 double theMinimum,
double theMaximum,
390 bool theIncludeOutOfRange )
392 QgsDebugMsg( QString(
"theBandNo = %1 theBinCount = %2 theMinimum = %3 theMaximum = %4 theSampleSize = %5" ).arg( theBandNo ).arg( theBinCount ).arg( theMinimum ).arg( theMaximum ).arg( theSampleSize ) );
395 initHistogram( myHistogram, theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );
400 if ( histogram == myHistogram )
407 int myBinCount = myHistogram.
binCount;
408 int myWidth = myHistogram.
width;
409 int myHeight = myHistogram.
height;
415 if ( myXBlockSize == 0 )
419 if ( myYBlockSize == 0 )
424 int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
425 int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;
427 double myXRes = myExtent.
width() / myWidth;
428 double myYRes = myExtent.
height() / myHeight;
430 double myMinimum = myHistogram.
minimum;
431 double myMaximum = myHistogram.
maximum;
435 double myerval = ( myMaximum - myMinimum ) / myHistogram.
binCount;
436 myMinimum -= 0.1 * myerval;
437 myMaximum += 0.1 * myerval;
439 QgsDebugMsg( QString(
"binCount = %1 myMinimum = %2 myMaximum = %3" ).arg( myHistogram.
binCount ).arg( myMinimum ).arg( myMaximum ) );
441 double myBinSize = ( myMaximum - myMinimum ) / myBinCount;
444 for (
int myYBlock = 0; myYBlock < myNYBlocks; myYBlock++ )
446 for (
int myXBlock = 0; myXBlock < myNXBlocks; myXBlock++ )
448 int myBlockWidth = qMin( myXBlockSize, myWidth - myXBlock * myXBlockSize );
449 int myBlockHeight = qMin( myYBlockSize, myHeight - myYBlock * myYBlockSize );
451 double xmin = myExtent.
xMinimum() + myXBlock * myXBlockSize * myXRes;
452 double xmax = xmin + myBlockWidth * myXRes;
453 double ymin = myExtent.
yMaximum() - myYBlock * myYBlockSize * myYRes;
454 double ymax = ymin - myBlockHeight * myYRes;
461 for (
size_t i = 0; i < (( size_t ) myBlockHeight ) * myBlockWidth; i++ )
467 double myValue = blk->
value( i );
469 int myBinIndex = static_cast <
int>( qFloor(( myValue - myMinimum ) / myBinSize ) ) ;
471 if (( myBinIndex < 0 || myBinIndex > ( myBinCount - 1 ) ) && !theIncludeOutOfRange )
475 if ( myBinIndex < 0 ) myBinIndex = 0;
476 if ( myBinIndex > ( myBinCount - 1 ) ) myBinIndex = myBinCount - 1;
485 myHistogram.
valid =
true;
490 for (
int i = 0; i < qMin( myHistogram.
histogramVector.size(), 500 ); i++ )
492 hist += QString::number( myHistogram.
histogramVector.value( i ) ) +
" ";
494 QgsDebugMsg(
"Histogram (max first 500 bins): " + hist );
501 double theLowerCount,
double theUpperCount,
502 double &theLowerValue,
double &theUpperValue,
506 QgsDebugMsg( QString(
"theBandNo = %1 theLowerCount = %2 theUpperCount = %3 theSampleSize = %4" ).arg( theBandNo ).arg( theLowerCount ).arg( theUpperCount ).arg( theSampleSize ) );
508 QgsRasterHistogram myHistogram =
histogram( theBandNo, 0, std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), theExtent, theSampleSize );
511 theLowerValue = std::numeric_limits<double>::quiet_NaN();
512 theUpperValue = std::numeric_limits<double>::quiet_NaN();
516 int myMinCount = (
int ) qRound( theLowerCount * myHistogram.
nonNullCount );
517 int myMaxCount = ( int ) qRound( theUpperCount * myHistogram.
nonNullCount );
518 bool myLowerFound =
false;
519 QgsDebugMsg( QString(
"binCount = %1 minimum = %2 maximum = %3 myBinXStep = %4" ).arg( myHistogram.
binCount ).arg( myHistogram.
minimum ).arg( myHistogram.
maximum ).arg( myBinXStep ) );
520 QgsDebugMsg( QString(
"myMinCount = %1 myMaxCount = %2" ).arg( myMinCount ).arg( myMaxCount ) );
522 for (
int myBin = 0; myBin < myHistogram.
histogramVector.size(); myBin++ )
525 myCount += myBinValue;
526 if ( !myLowerFound && myCount > myMinCount )
528 theLowerValue = myHistogram.
minimum + myBin * myBinXStep;
531 if ( myCount >= myMaxCount )
533 theUpperValue = myHistogram.
minimum + myBin * myBinXStep;
541 QStringList abilitiesList;
551 abilitiesList +=
tr(
"Identify" );
556 abilitiesList +=
tr(
"Create Datasources" );
561 abilitiesList +=
tr(
"Remove Datasources" );
566 abilitiesList +=
tr(
"Build Pyramids" );
569 QgsDebugMsg(
"Capability: " + abilitiesList.join(
", " ) );
571 return abilitiesList.join(
", " );