Skip to content
Permalink
Browse files

Better array generation for paletted raster renderer

  • Loading branch information
mhugent committed Jan 20, 2012
1 parent f16ca52 commit 15fe4da7e8c652889793a426c714aa432e00db69
Showing with 15 additions and 3 deletions.
  1. +15 −3 src/core/raster/qgsrasterlayer.cpp
@@ -597,23 +597,35 @@ void QgsRasterLayer::setRendererForDrawingStyle( const DrawingStyle & theDrawin
{
case PalettedColor:
{
//todo: go through list and take maximum value (it could be that entries don't start at 0 or indices are not contiguous
int grayBand = bandNumber( grayBandName() );
QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( rasterShader()->rasterShaderFunction() );
if ( colorRampShader )
{
QList<QgsColorRampShader::ColorRampItem> colorEntries = colorRampShader->colorRampItemList();
QColor* colorArray = new QColor[ colorEntries.size()];

//go through list and take maximum value (it could be that entries don't start at 0 or indices are not contiguous)
int colorArraySize = 0;
QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = colorEntries.constBegin();
for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
{
if ( colorIt->value > colorArraySize )
{
colorArraySize = ( int )( colorIt->value );
}
}

colorArraySize += 1; //usually starts at 0
QColor* colorArray = new QColor[ colorArraySize ];
colorIt = colorEntries.constBegin();
for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
{
colorArray[( int )( colorIt->value )] = colorIt->color;
}

renderer = new QgsPalettedRasterRenderer( mDataProvider,
grayBand,
colorArray,
colorEntries.size() );
colorArraySize );
}
else //try to get it from the color table
{

0 comments on commit 15fe4da

Please sign in to comment.
You can’t perform that action at this time.