Skip to content

Commit

Permalink
fix handling discrete colormaps in continuous mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pierstitus authored and nyalldawson committed Jun 2, 2016
1 parent 5893647 commit cf72b59
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Expand Up @@ -367,7 +367,22 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
entryValues.reserve( numberOfEntries );
if ( discrete )
{
double intervalDiff = ( max - min ) * ( numberOfEntries - 1 ) / numberOfEntries;
double intervalDiff = max - min;

// remove last class when ColorRamp is gradient and discrete, as they are implemented with an extra stop
QgsVectorGradientColorRampV2* colorGradientRamp = dynamic_cast<QgsVectorGradientColorRampV2*>( colorRamp );
if ( colorGradientRamp != NULL && colorGradientRamp->isDiscrete() )
{
numberOfEntries--;
}
else
{
// if color ramp is continuous scale values to get equally distributed classes.
// Doesn't work perfectly when stops are non equally distributed.
intervalDiff *= ( numberOfEntries - 1 ) / numberOfEntries;
}

// skip first value (always 0.0)
for ( int i = 1; i < numberOfEntries; ++i )
{
double value = colorRamp->value( i );
Expand Down

0 comments on commit cf72b59

Please sign in to comment.