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 (
qgssize i = 0; i < ((
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 ) );
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;
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 QgsDebugMsg( QString(
"theBandNo = %1 theBinCount = %2 theMinimum = %3 theMaximum = %4 theSampleSize = %5" ).arg( theBandNo ).arg( theBinCount ).arg( theMinimum ).arg( theMaximum ).arg( theSampleSize ) );
382 initHistogram( myHistogram, theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );
386 if ( histogram == myHistogram )
397 double theMinimum,
double theMaximum,
400 bool theIncludeOutOfRange )
402 QgsDebugMsg( QString(
"theBandNo = %1 theBinCount = %2 theMinimum = %3 theMaximum = %4 theSampleSize = %5" ).arg( theBandNo ).arg( theBinCount ).arg( theMinimum ).arg( theMaximum ).arg( theSampleSize ) );
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;
449 QgsDebugMsg( QString(
"binCount = %1 myMinimum = %2 myMaximum = %3" ).arg( myHistogram.
binCount ).arg( myMinimum ).arg( myMaximum ) );
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 < ((
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;
500 for (
int i = 0; i < qMin( myHistogram.
histogramVector.size(), 500 ); i++ )
502 hist += QString::number( myHistogram.
histogramVector.value( i ) ) +
" ";
504 QgsDebugMsg(
"Histogram (max first 500 bins): " + hist );
511 double theLowerCount,
double theUpperCount,
512 double &theLowerValue,
double &theUpperValue,
516 QgsDebugMsg( QString(
"theBandNo = %1 theLowerCount = %2 theUpperCount = %3 theSampleSize = %4" ).arg( theBandNo ).arg( theLowerCount ).arg( theUpperCount ).arg( theSampleSize ) );
521 theLowerValue = std::numeric_limits<double>::quiet_NaN();
522 theUpperValue = std::numeric_limits<double>::quiet_NaN();
536 int myMinCount = (
int ) qRound( theLowerCount * myHistogram.
nonNullCount );
537 int myMaxCount = ( int ) qRound( theUpperCount * myHistogram.
nonNullCount );
538 bool myLowerFound =
false;
539 QgsDebugMsg( QString(
"binCount = %1 minimum = %2 maximum = %3 myBinXStep = %4" ).arg( myHistogram.
binCount ).arg( myHistogram.
minimum ).arg( myHistogram.
maximum ).arg( myBinXStep ) );
540 QgsDebugMsg( QString(
"myMinCount = %1 myMaxCount = %2" ).arg( myMinCount ).arg( myMaxCount ) );
542 for (
int myBin = 0; myBin < myHistogram.
histogramVector.size(); myBin++ )
545 myCount += myBinValue;
546 if ( !myLowerFound && myCount > myMinCount )
548 theLowerValue = myHistogram.
minimum + myBin * myBinXStep;
550 QgsDebugMsg( QString(
"found lowerValue %1 at bin %2" ).arg( theLowerValue ).arg( myBin ) );
552 if ( myCount >= myMaxCount )
554 theUpperValue = myHistogram.
minimum + myBin * myBinXStep;
555 QgsDebugMsg( QString(
"found upperValue %1 at bin %2" ).arg( theUpperValue ).arg( myBin ) );
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 );
574 QStringList abilitiesList;
584 abilitiesList +=
tr(
"Identify" );
589 abilitiesList +=
tr(
"Create Datasources" );
594 abilitiesList +=
tr(
"Remove Datasources" );
599 abilitiesList +=
tr(
"Build Pyramids" );
602 QgsDebugMsg(
"Capability: " + abilitiesList.join(
", " ) );
604 return abilitiesList.join(
", " );