Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Consider user defined colors for paletted rasters
  • Loading branch information
mhugent committed Jan 19, 2012
1 parent ab911fe commit f16ca52
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -597,19 +597,36 @@ void QgsRasterLayer::setRendererForDrawingStyle( const DrawingStyle & theDrawin
{
case PalettedColor:
{
//create color array for renderer
//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() );
QList<QgsColorRampShader::ColorRampItem> itemList = mRasterStatsList[ grayBand - 1].colorTable;
QColor* colorArray = new QColor[itemList.size()];
QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = itemList.constBegin();
for ( ; colorIt != itemList.constEnd(); ++colorIt )
QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( rasterShader()->rasterShaderFunction() );
if ( colorRampShader )
{
colorArray[( int )colorIt->value] = colorIt->color;
QList<QgsColorRampShader::ColorRampItem> colorEntries = colorRampShader->colorRampItemList();
QColor* colorArray = new QColor[ colorEntries.size()];
QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = colorEntries.constBegin();
for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
{
colorArray[( int )( colorIt->value )] = colorIt->color;
}

renderer = new QgsPalettedRasterRenderer( mDataProvider,
grayBand,
colorArray,
colorEntries.size() );
}
else //try to get it from the color table
{
QList<QgsColorRampShader::ColorRampItem> itemList = mRasterStatsList[ grayBand - 1].colorTable;
QColor* colorArray = new QColor[itemList.size()];
QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = itemList.constBegin();
for ( ; colorIt != itemList.constEnd(); ++colorIt )
{
colorArray[( int )colorIt->value] = colorIt->color;
}
renderer = new QgsPalettedRasterRenderer( mDataProvider,
grayBand, colorArray, itemList.size() );
}
renderer = new QgsPalettedRasterRenderer( mDataProvider,
grayBand,
colorArray,
itemList.size() );
break;
}
case MultiBandSingleBandGray:
Expand Down

0 comments on commit f16ca52

Please sign in to comment.