Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #35923 from elpaso/raster-quantile-shader-increase…
Browse files Browse the repository at this point in the history
…-sample-size-3_12

[backport] Raster quantile shader increase sample size and bin count
  • Loading branch information
elpaso committed Apr 23, 2020
2 parents 566afd9 + 95b510b commit 3811e4c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/core/raster/qgscolorrampshader.cpp
Expand Up @@ -204,11 +204,12 @@ void QgsColorRampShader::classifyColorRamp( const int classes, const int band, c
{
// Quantile
if ( band < 0 || !input )
return; // quantile classificationr requires a valid band, minMaxOrigin, and input
return; // quantile classification requires a valid band, minMaxOrigin, and input

double cut1 = std::numeric_limits<double>::quiet_NaN();
double cut2 = std::numeric_limits<double>::quiet_NaN();
int sampleSize = 250000;
// Note: the sample size in other parts of QGIS appears to be 25000, it is ten times here.
const int sampleSize = 250000 * 10;

// 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
16 changes: 11 additions & 5 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -347,18 +347,24 @@ 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;

// for Int16/Int32 make sure bin count <= actual range, because there is no sense in having
// bins at fractional values
if ( !mInput && (
mySrcDataType == Qgis::Int16 || mySrcDataType == Qgis::Int32 ||
mySrcDataType == Qgis::UInt16 || mySrcDataType == Qgis::UInt32 ) )
{
if ( myBinCount > histogram.maximum - histogram.minimum + 1 )
myBinCount = int( std::ceil( histogram.maximum - histogram.minimum + 1 ) );
myBinCount = std::min( histogram.width * histogram.height, static_cast<int>( std::ceil( histogram.maximum - histogram.minimum + 1 ) ) );
}
else
{
// This is for not integer types:
myBinCount = std::min( 2000, histogram.width * histogram.height );
}
}
}
Expand Down

0 comments on commit 3811e4c

Please sign in to comment.