Skip to content

Commit

Permalink
Fix single band gray with alpha raster type not recognized (fix ##4159)
Browse files Browse the repository at this point in the history
- Add band color interpretation for WCS provider (from GDAL provider)
  • Loading branch information
dakcarto committed Jun 4, 2015
1 parent 08f2f41 commit 71ceab8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -708,7 +708,19 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
QgsDebugMsg( "dataType = " + QString::number( mDataProvider->dataType( 1 ) ) );
if (( mDataProvider->bandCount() > 1 ) )
{
mRasterType = Multiband;
// handle singleband gray with alpha
if ( mDataProvider->bandCount() == 2
&& (( mDataProvider->colorInterpretation( 1 ) == QgsRaster::GrayIndex
&& mDataProvider->colorInterpretation( 2 ) == QgsRaster::AlphaBand )
|| ( mDataProvider->colorInterpretation( 1 ) == QgsRaster::AlphaBand
&& mDataProvider->colorInterpretation( 2 ) == QgsRaster::GrayIndex ) ) )
{
mRasterType = GrayOrUndefined;
}
else
{
mRasterType = Multiband;
}
}
else if ( mDataProvider->dataType( 1 ) == QGis::ARGB32
|| mDataProvider->dataType( 1 ) == QGis::ARGB32_Premultiplied )
Expand Down
6 changes: 6 additions & 0 deletions src/providers/wcs/qgswcsprovider.cpp
Expand Up @@ -913,6 +913,12 @@ QList<QgsColorRampShader::ColorRampItem> QgsWcsProvider::colorTable( int theBand
return mColorTables.value( theBandNumber - 1 );
}

int QgsWcsProvider::colorInterpretation( int bandNo ) const
{
GDALRasterBandH myGdalBand = GDALGetRasterBand( mCachedGdalDataset, bandNo );
return colorInterpretationFromGdal( GDALGetRasterColorInterpretation( myGdalBand ) );
}


bool QgsWcsProvider::parseServiceExceptionReportDom( QByteArray const & xml, const QString& wcsVersion, QString& errorTitle, QString& errorText )
{
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wcs/qgswcsprovider.h
Expand Up @@ -178,6 +178,8 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
void reloadData() override;
QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo )const override;

int colorInterpretation( int bandNo ) const override;

static QMap<QString, QString> supportedMimes();

/**
Expand Down

0 comments on commit 71ceab8

Please sign in to comment.