@@ -60,9 +60,15 @@ QList<QgsColorRampShader::ColorRampItem> QgsGdalProviderBase::colorTable( GDALDa
6060 {
6161 QgsDebugMsg ( " Color table found" );
6262
63- // TODO: load category labels and use them for ColorRampItem.label once
64- // GDALGetCategoryNames C function is added to GDAL, see #8886
65- // char ** categoryNames = GDALGetCategoryNames( myGdalBand );
63+ // load category labels
64+ char ** categoryNames = GDALGetRasterCategoryNames ( myGdalBand );
65+ QVector<QString> labels;
66+ int i = 0 ;
67+ while ( categoryNames[i] )
68+ {
69+ labels.append ( QString ( categoryNames[i] ) );
70+ i++;
71+ }
6672
6773 int myEntryCount = GDALGetColorEntryCount ( myGdalColorTable );
6874 GDALColorInterp myColorInterpretation = GDALGetRasterColorInterpretation ( myGdalBand );
@@ -81,20 +87,25 @@ QList<QgsColorRampShader::ColorRampItem> QgsGdalProviderBase::colorTable( GDALDa
8187 }
8288 else
8389 {
90+ QString label = labels.value ( myIterator );
91+ if ( label.isEmpty () )
92+ {
93+ label = QString::number ( myIterator );
94+ }
8495 // Branch on the color interpretation type
8596 if ( myColorInterpretation == GCI_GrayIndex )
8697 {
8798 QgsColorRampShader::ColorRampItem myColorRampItem;
88- myColorRampItem.label = " " ;
8999 myColorRampItem.value = ( double )myIterator;
100+ myColorRampItem.label = label;
90101 myColorRampItem.color = QColor::fromRgb ( myColorEntry->c1 , myColorEntry->c1 , myColorEntry->c1 , myColorEntry->c4 );
91102 ct.append ( myColorRampItem );
92103 }
93104 else if ( myColorInterpretation == GCI_PaletteIndex )
94105 {
95106 QgsColorRampShader::ColorRampItem myColorRampItem;
96107 myColorRampItem.value = ( double )myIterator;
97- myColorRampItem.label = QString::number ( myColorRampItem. value ) ;
108+ myColorRampItem.label = label ;
98109 // Branch on palette interpretation
99110 if ( myPaletteInterpretation == GPI_RGB )
100111 {
0 commit comments