Skip to content
Permalink
Browse files

Consider user defined colors for paletted rasters

  • Loading branch information
mhugent committed Jan 19, 2012
1 parent ab911fe commit f16ca52524a14634191e6ec88a81ea1be31461e7
Showing with 27 additions and 10 deletions.
  1. +27 −10 src/core/raster/qgsrasterlayer.cpp
@@ -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:

0 comments on commit f16ca52

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