Skip to content

Commit cf72b59

Browse files
pierstitusnyalldawson
authored andcommittedJun 2, 2016
fix handling discrete colormaps in continuous mode
1 parent 5893647 commit cf72b59

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed
 

‎src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,22 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
367367
entryValues.reserve( numberOfEntries );
368368
if ( discrete )
369369
{
370-
double intervalDiff = ( max - min ) * ( numberOfEntries - 1 ) / numberOfEntries;
370+
double intervalDiff = max - min;
371+
372+
// remove last class when ColorRamp is gradient and discrete, as they are implemented with an extra stop
373+
QgsVectorGradientColorRampV2* colorGradientRamp = dynamic_cast<QgsVectorGradientColorRampV2*>( colorRamp );
374+
if ( colorGradientRamp != NULL && colorGradientRamp->isDiscrete() )
375+
{
376+
numberOfEntries--;
377+
}
378+
else
379+
{
380+
// if color ramp is continuous scale values to get equally distributed classes.
381+
// Doesn't work perfectly when stops are non equally distributed.
382+
intervalDiff *= ( numberOfEntries - 1 ) / numberOfEntries;
383+
}
384+
385+
// skip first value (always 0.0)
371386
for ( int i = 1; i < numberOfEntries; ++i )
372387
{
373388
double value = colorRamp->value( i );

0 commit comments

Comments
 (0)
Please sign in to comment.