Skip to content

Commit

Permalink
Increase default bin size for raster histograms
Browse files Browse the repository at this point in the history
Fixes #35465 but it is still and arbitrary value,
better approaches would require to calculate other
dispersion indexes and they seem impractical (inefficient)
in this case.

See for example: https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule
  • Loading branch information
elpaso committed Apr 11, 2020
1 parent 7a9c3c6 commit 98261bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/raster/qgscolorrampshader.cpp
Expand Up @@ -208,7 +208,7 @@ void QgsColorRampShader::classifyColorRamp( const int classes, const int band, c

double cut1 = std::numeric_limits<double>::quiet_NaN();
double cut2 = std::numeric_limits<double>::quiet_NaN();
int sampleSize = 250000;
const int sampleSize = 250000;

// set min and max from histogram, used later to calculate number of decimals to display
input->cumulativeCut( band, 0.0, 1.0, min, max, extent, sampleSize );
Expand Down
9 changes: 6 additions & 3 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -347,9 +347,12 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &histogram,
}
else
{
// There is no best default value, to display something reasonable in histogram chart, binCount should be small, OTOH, to get precise data for cumulative cut, the number should be big. Because it is easier to define fixed lower value for the chart, we calc optimum binCount for higher resolution (to avoid calculating that where histogram() is used. In any any case, it does not make sense to use more than width*height;
myBinCount = histogram.width * histogram.height;
if ( myBinCount > 1000 ) myBinCount = 1000;
// There is no best default value, to display something reasonable in histogram chart,
// binCount should be small, OTOH, to get precise data for cumulative cut, the number should be big.
// Because it is easier to define fixed lower value for the chart, we calc optimum binCount
// for higher resolution (to avoid calculating that where histogram() is used. In any any case,
// it does not make sense to use more than width*height;
myBinCount = std::min( 2000, histogram.width * histogram.height );

// for Int16/Int32 make sure bin count <= actual range, because there is no sense in having
// bins at fractional values
Expand Down

0 comments on commit 98261bc

Please sign in to comment.