Skip to content

Commit 3811e4c

Browse files
authoredApr 23, 2020
Merge pull request #35923 from elpaso/raster-quantile-shader-increase-sample-size-3_12
[backport] Raster quantile shader increase sample size and bin count
2 parents 566afd9 + 95b510b commit 3811e4c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed
 

‎src/core/raster/qgscolorrampshader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,12 @@ void QgsColorRampShader::classifyColorRamp( const int classes, const int band, c
204204
{
205205
// Quantile
206206
if ( band < 0 || !input )
207-
return; // quantile classificationr requires a valid band, minMaxOrigin, and input
207+
return; // quantile classification requires a valid band, minMaxOrigin, and input
208208

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

213214
// set min and max from histogram, used later to calculate number of decimals to display
214215
input->cumulativeCut( band, 0.0, 1.0, min, max, extent, sampleSize );

‎src/core/raster/qgsrasterinterface.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,18 +347,24 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &histogram,
347347
}
348348
else
349349
{
350-
// 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;
351-
myBinCount = histogram.width * histogram.height;
352-
if ( myBinCount > 1000 ) myBinCount = 1000;
350+
// There is no best default value, to display something reasonable in histogram chart,
351+
// binCount should be small, OTOH, to get precise data for cumulative cut, the number should be big.
352+
// Because it is easier to define fixed lower value for the chart, we calc optimum binCount
353+
// for higher resolution (to avoid calculating that where histogram() is used. In any any case,
354+
// it does not make sense to use more than width*height;
353355

354356
// for Int16/Int32 make sure bin count <= actual range, because there is no sense in having
355357
// bins at fractional values
356358
if ( !mInput && (
357359
mySrcDataType == Qgis::Int16 || mySrcDataType == Qgis::Int32 ||
358360
mySrcDataType == Qgis::UInt16 || mySrcDataType == Qgis::UInt32 ) )
359361
{
360-
if ( myBinCount > histogram.maximum - histogram.minimum + 1 )
361-
myBinCount = int( std::ceil( histogram.maximum - histogram.minimum + 1 ) );
362+
myBinCount = std::min( histogram.width * histogram.height, static_cast<int>( std::ceil( histogram.maximum - histogram.minimum + 1 ) ) );
363+
}
364+
else
365+
{
366+
// This is for not integer types:
367+
myBinCount = std::min( 2000, histogram.width * histogram.height );
362368
}
363369
}
364370
}

0 commit comments

Comments
 (0)
Please sign in to comment.