Skip to content
Permalink
Browse files
Improve random color generation for unique raster values
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent 19403f6 commit e2a82a073d3a0fded641bb2bb555332f1e8074fb
Showing with 22 additions and 0 deletions.
  1. +11 −0 src/core/raster/qgspalettedrasterrenderer.cpp
  2. +11 −0 src/gui/raster/qgspalettedrendererwidget.cpp
@@ -437,6 +437,17 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromRas
if ( ramp )
{
int i = 0;

if ( QgsRandomColorRamp *randomRamp = dynamic_cast<QgsRandomColorRamp *>( ramp ) )
{
//ramp is a random colors ramp, so inform it of the total number of required colors
//this allows the ramp to pregenerate a set of visually distinctive colors
randomRamp->setTotalColorCount( data.count() );
}

if ( presentValues > 1 )
presentValues -= 1; //avoid duplicate first color

QgsPalettedRasterRenderer::ClassData::iterator cIt = data.begin();
for ( ; cIt != data.end(); ++cIt )
{
@@ -318,6 +318,17 @@ void QgsPalettedRendererWidget::applyColorRamp()

double numberOfEntries = data.count();
int i = 0;

if ( QgsRandomColorRamp *randomRamp = dynamic_cast<QgsRandomColorRamp *>( ramp.get() ) )
{
//ramp is a random colors ramp, so inform it of the total number of required colors
//this allows the ramp to pregenerate a set of visually distinctive colors
randomRamp->setTotalColorCount( numberOfEntries );
}

if ( numberOfEntries > 1 )
numberOfEntries -= 1; //avoid duplicate first color

for ( ; cIt != data.end(); ++cIt )
{
cIt->color = ramp->color( i / numberOfEntries );

0 comments on commit e2a82a0

Please sign in to comment.