Skip to content
Permalink
Browse files

Load raster category names by GDAL provider, fixes #8886

  • Loading branch information
blazek committed Nov 3, 2013
1 parent 37d365c commit 8bdaf42dbaec240151eacaa9a28e02f49a53fd66
Showing with 26 additions and 7 deletions.
  1. +10 −2 src/core/raster/qgsrasterrendererregistry.cpp
  2. +16 −5 src/providers/gdal/qgsgdalproviderbase.cpp
@@ -132,15 +132,23 @@ QgsRasterRenderer* QgsRasterRendererRegistry::defaultRendererForDrawingStyle( co
colorArraySize += 1; //usually starts at 0
QColor* colorArray = new QColor[ colorArraySize ];
colorIt = colorEntries.constBegin();
QVector<QString> labels;
for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
{
colorArray[( int )( colorIt->value )] = colorIt->color;
int idx = ( int )( colorIt->value );
colorArray[idx] = colorIt->color;
if ( !colorIt->label.isEmpty() )
{
if ( labels.size() <= idx ) labels.resize( idx + 1 );
labels[idx] = colorIt->label;
}
}

renderer = new QgsPalettedRasterRenderer( provider,
grayBand,
colorArray,
colorArraySize );
colorArraySize,
labels );
}
break;
case QgsRaster::MultiBandSingleBandGray:
@@ -60,9 +60,15 @@ QList<QgsColorRampShader::ColorRampItem> QgsGdalProviderBase::colorTable( GDALDa
{
QgsDebugMsg( "Color table found" );

// TODO: load category labels and use them for ColorRampItem.label once
// GDALGetCategoryNames C function is added to GDAL, see #8886
//char ** categoryNames = GDALGetCategoryNames( myGdalBand );
// load category labels
char ** categoryNames = GDALGetRasterCategoryNames( myGdalBand );
QVector<QString> labels;
int i = 0;
while ( categoryNames[i] )
{
labels.append( QString( categoryNames[i] ) );
i++;
}

int myEntryCount = GDALGetColorEntryCount( myGdalColorTable );
GDALColorInterp myColorInterpretation = GDALGetRasterColorInterpretation( myGdalBand );
@@ -81,20 +87,25 @@ QList<QgsColorRampShader::ColorRampItem> QgsGdalProviderBase::colorTable( GDALDa
}
else
{
QString label = labels.value( myIterator );
if ( label.isEmpty() )
{
label = QString::number( myIterator );
}
//Branch on the color interpretation type
if ( myColorInterpretation == GCI_GrayIndex )
{
QgsColorRampShader::ColorRampItem myColorRampItem;
myColorRampItem.label = "";
myColorRampItem.value = ( double )myIterator;
myColorRampItem.label = label;
myColorRampItem.color = QColor::fromRgb( myColorEntry->c1, myColorEntry->c1, myColorEntry->c1, myColorEntry->c4 );
ct.append( myColorRampItem );
}
else if ( myColorInterpretation == GCI_PaletteIndex )
{
QgsColorRampShader::ColorRampItem myColorRampItem;
myColorRampItem.value = ( double )myIterator;
myColorRampItem.label = QString::number( myColorRampItem.value );
myColorRampItem.label = label;
//Branch on palette interpretation
if ( myPaletteInterpretation == GPI_RGB )
{

3 comments on commit 8bdaf42

@dakcarto

This comment has been minimized.

Copy link
Member

@dakcarto dakcarto replied Nov 3, 2013

Hi Radim,

Something about this commit is causing QGIS to crash on Mac (though I think it is unrelated to the platform). See the following crash report.

@blazek

This comment has been minimized.

Copy link
Member Author

@blazek blazek replied Nov 4, 2013

It should be fixed in c59cd92, sorry.

@blazek

This comment has been minimized.

Copy link
Member Author

@blazek blazek replied Nov 4, 2013

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