Skip to content

Commit 71ceab8

Browse files
committedJun 4, 2015
Fix single band gray with alpha raster type not recognized (fix ##4159)
- Add band color interpretation for WCS provider (from GDAL provider)
1 parent 08f2f41 commit 71ceab8

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
 

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,19 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
708708
QgsDebugMsg( "dataType = " + QString::number( mDataProvider->dataType( 1 ) ) );
709709
if (( mDataProvider->bandCount() > 1 ) )
710710
{
711-
mRasterType = Multiband;
711+
// handle singleband gray with alpha
712+
if ( mDataProvider->bandCount() == 2
713+
&& (( mDataProvider->colorInterpretation( 1 ) == QgsRaster::GrayIndex
714+
&& mDataProvider->colorInterpretation( 2 ) == QgsRaster::AlphaBand )
715+
|| ( mDataProvider->colorInterpretation( 1 ) == QgsRaster::AlphaBand
716+
&& mDataProvider->colorInterpretation( 2 ) == QgsRaster::GrayIndex ) ) )
717+
{
718+
mRasterType = GrayOrUndefined;
719+
}
720+
else
721+
{
722+
mRasterType = Multiband;
723+
}
712724
}
713725
else if ( mDataProvider->dataType( 1 ) == QGis::ARGB32
714726
|| mDataProvider->dataType( 1 ) == QGis::ARGB32_Premultiplied )

‎src/providers/wcs/qgswcsprovider.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,12 @@ QList<QgsColorRampShader::ColorRampItem> QgsWcsProvider::colorTable( int theBand
913913
return mColorTables.value( theBandNumber - 1 );
914914
}
915915

916+
int QgsWcsProvider::colorInterpretation( int bandNo ) const
917+
{
918+
GDALRasterBandH myGdalBand = GDALGetRasterBand( mCachedGdalDataset, bandNo );
919+
return colorInterpretationFromGdal( GDALGetRasterColorInterpretation( myGdalBand ) );
920+
}
921+
916922

917923
bool QgsWcsProvider::parseServiceExceptionReportDom( QByteArray const & xml, const QString& wcsVersion, QString& errorTitle, QString& errorText )
918924
{

‎src/providers/wcs/qgswcsprovider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
178178
void reloadData() override;
179179
QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo )const override;
180180

181+
int colorInterpretation( int bandNo ) const override;
182+
181183
static QMap<QString, QString> supportedMimes();
182184

183185
/**

0 commit comments

Comments
 (0)
Please sign in to comment.