26 changes: 25 additions & 1 deletion src/core/raster/qgsmultibandcolorrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
int redVal = 0;
int greenVal = 0;
int blueVal = 0;
int redDataVal = 0;
int greenDataVal = 0;
int blueDataVal = 0;
QRgb defaultColor = qRgba( 255, 255, 255, 0 );
double currentOpacity = mOpacity; //opacity (between 0 and 1)

Expand All @@ -243,14 +246,17 @@ void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
if ( mRedBand > 0 )
{
redVal = readValue( redData, redType, currentRasterPos );
redDataVal = redVal;
}
if ( mGreenBand > 0 )
{
greenVal = readValue( greenData, greenType, currentRasterPos );
greenDataVal = greenVal;
}
if ( mBlueBand > 0 )
{
blueVal = readValue( blueData, blueType, currentRasterPos );
blueDataVal = blueVal;
}

//apply default color if red, green or blue not in displayable range
Expand Down Expand Up @@ -288,7 +294,7 @@ void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
currentOpacity = mOpacity;
if ( mRasterTransparency )
{
currentOpacity = mRasterTransparency->alphaValue( redVal, greenVal, blueVal, mOpacity * 255 ) / 255.0;
currentOpacity = mRasterTransparency->alphaValue( redDataVal, greenDataVal, blueDataVal, mOpacity * 255 ) / 255.0;
}
if ( mAlphaBand > 0 )
{
Expand Down Expand Up @@ -351,3 +357,21 @@ void QgsMultiBandColorRenderer::writeXML( QDomDocument& doc, QDomElement& parent
}
parentElem.appendChild( rasterRendererElem );
}

QList<int> QgsMultiBandColorRenderer::usesBands() const
{
QList<int> bandList;
if ( mRedBand != -1 )
{
bandList << mRedBand;
}
if ( mGreenBand != -1 )
{
bandList << mGreenBand;
}
if ( mBlueBand != -1 )
{
bandList << mBlueBand;
}
return bandList;
}
2 changes: 2 additions & 0 deletions src/core/raster/qgsmultibandcolorrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class CORE_EXPORT QgsMultiBandColorRenderer: public QgsRasterRenderer

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;

QList<int> usesBands() const;

private:
int mRedBand;
int mGreenBand;
Expand Down
10 changes: 10 additions & 0 deletions src/core/raster/qgspalettedrasterrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,13 @@ void QgsPalettedRasterRenderer::legendSymbologyItems( QList< QPair< QString, QCo
symbolItems.push_back( qMakePair( QString::number( i ), mColors[i] ) );
}
}

QList<int> QgsPalettedRasterRenderer::usesBands() const
{
QList<int> bandList;
if ( mBandNumber != -1 )
{
bandList << mBandNumber;
}
return bandList;
}
2 changes: 2 additions & 0 deletions src/core/raster/qgspalettedrasterrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CORE_EXPORT QgsPalettedRasterRenderer: public QgsRasterRenderer

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;

QList<int> usesBands() const;

private:
int mBandNumber;
/**Color array*/
Expand Down
12 changes: 12 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,18 @@ bool QgsRasterLayer::identify( const QgsPoint& thePoint, QMap<QString, QString>&
return ( mDataProvider->identify( thePoint, theResults ) );
}

bool QgsRasterLayer::identify( const QgsPoint & point, QMap<int, QString>& results )
{
if ( !mDataProvider )
{
return false;
}

results.clear();
return mDataProvider->identify( point, results );
}


/**
* @note The arbitraryness of the returned document is enforced by WMS standards up to at least v1.3.0
*
Expand Down
3 changes: 3 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Identify raster value(s) found on the point position */
bool identify( const QgsPoint & point, QMap<QString, QString>& results );

/** \brief Identify raster value(s) found on the point position */
bool identify( const QgsPoint & point, QMap<int, QString>& results );

/** \brief Identify arbitrary details from the WMS server found on the point position */
QString identifyAsText( const QgsPoint & point );

Expand Down
3 changes: 3 additions & 0 deletions src/core/raster/qgsrasterrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class CORE_EXPORT QgsRasterRenderer
/**Sets base class members from xml. Usually called from create() methods of subclasses*/
void readXML( const QDomElement& rendererElem );

/**Returns a list of band numbers used by the renderer*/
virtual QList<int> usesBands() const { return QList<int>(); }

protected:
inline double readValue( void *data, QgsRasterDataProvider::DataType type, int index );

Expand Down
23 changes: 23 additions & 0 deletions src/core/raster/qgsrasterrendererregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,29 @@ QgsRasterRenderer* QgsRasterRendererRegistry::defaultRendererForDrawingStyle( co
break;
}

QgsRasterTransparency* tr = new QgsRasterTransparency(); //renderer takes ownership
int bandCount = renderer->usesBands().size();
if ( bandCount == 1 )
{
QList<QgsRasterTransparency::TransparentSingleValuePixel> transparentSingleList;
QgsRasterTransparency::TransparentSingleValuePixel singleEntry;
singleEntry.pixelValue = provider->noDataValue();
singleEntry.percentTransparent = 100;
transparentSingleList.push_back( singleEntry );
tr->setTransparentSingleValuePixelList( transparentSingleList );
}
else if ( bandCount == 3 )
{
QList<QgsRasterTransparency::TransparentThreeValuePixel> transparentThreeValueList;
QgsRasterTransparency::TransparentThreeValuePixel threeValueEntry;
threeValueEntry.red = provider->noDataValue();
threeValueEntry.green = provider->noDataValue();
threeValueEntry.blue = provider->noDataValue();
threeValueEntry.percentTransparent = 100;
transparentThreeValueList.push_back( threeValueEntry );
tr->setTransparentThreeValuePixelList( transparentThreeValueList );
}
renderer->setRasterTransparency( tr );
#if 0
if ( !renderer )
{
Expand Down
10 changes: 10 additions & 0 deletions src/core/raster/qgssinglebandcolordatarenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,13 @@ void QgsSingleBandColorDataRenderer::writeXML( QDomDocument& doc, QDomElement& p
rasterRendererElem.setAttribute( "band", mBand );
parentElem.appendChild( rasterRendererElem );
}

QList<int> QgsSingleBandColorDataRenderer::usesBands() const
{
QList<int> bandList;
if ( mBand != -1 )
{
bandList << mBand;
}
return bandList;
}
2 changes: 2 additions & 0 deletions src/core/raster/qgssinglebandcolordatarenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class CORE_EXPORT QgsSingleBandColorDataRenderer: public QgsRasterRenderer

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;

QList<int> usesBands() const;

private:
int mBand;
};
Expand Down
10 changes: 10 additions & 0 deletions src/core/raster/qgssinglebandgrayrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,13 @@ void QgsSingleBandGrayRenderer::legendSymbologyItems( QList< QPair< QString, QCo
symbolItems.push_back( qMakePair( QString::number( mContrastEnhancement->maximumValue() ), QColor( 255, 255, 255 ) ) );
}
}

QList<int> QgsSingleBandGrayRenderer::usesBands() const
{
QList<int> bandList;
if ( mGrayBand != -1 )
{
bandList << mGrayBand;
}
return bandList;
}
2 changes: 2 additions & 0 deletions src/core/raster/qgssinglebandgrayrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class CORE_EXPORT QgsSingleBandGrayRenderer: public QgsRasterRenderer

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;

QList<int> usesBands() const;

private:
int mGrayBand;
QgsContrastEnhancement* mContrastEnhancement;
Expand Down
10 changes: 10 additions & 0 deletions src/core/raster/qgssinglebandpseudocolorrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,13 @@ void QgsSingleBandPseudoColorRenderer::legendSymbologyItems( QList< QPair< QStri
}
}
}

QList<int> QgsSingleBandPseudoColorRenderer::usesBands() const
{
QList<int> bandList;
if ( mBand != -1 )
{
bandList << mBand;
}
return bandList;
}
2 changes: 2 additions & 0 deletions src/core/raster/qgssinglebandpseudocolorrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class CORE_EXPORT QgsSingleBandPseudoColorRenderer: public QgsRasterRenderer

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;

QList<int> usesBands() const;

private:
QgsRasterShader* mShader;
int mBand;
Expand Down
61 changes: 61 additions & 0 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,67 @@ int QgsGdalProvider::yBlockSize() const
int QgsGdalProvider::xSize() const { return mWidth; }
int QgsGdalProvider::ySize() const { return mHeight; }

bool QgsGdalProvider::identify( const QgsPoint & point, QMap<int, QString>& results )
{
// QgsDebugMsg( "Entered" );
if ( !mExtent.contains( point ) )
{
// Outside the raster
for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
{
results[ i ] = tr( "out of extent" );
}
}
else
{
double x = point.x();
double y = point.y();

// Calculate the row / column where the point falls
double xres = ( mExtent.xMaximum() - mExtent.xMinimum() ) / mWidth;
double yres = ( mExtent.yMaximum() - mExtent.yMinimum() ) / mHeight;

// Offset, not the cell index -> flor
int col = ( int ) floor(( x - mExtent.xMinimum() ) / xres );
int row = ( int ) floor(( mExtent.yMaximum() - y ) / yres );

// QgsDebugMsg( "row = " + QString::number( row ) + " col = " + QString::number( col ) );

for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
{
GDALRasterBandH gdalBand = GDALGetRasterBand( mGdalDataset, i );
double value;

CPLErr err = GDALRasterIO( gdalBand, GF_Read, col, row, 1, 1,
&value, 1, 1, GDT_Float64, 0, 0 );

if ( err != CPLE_None )
{
QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
}

//double value = readValue( data, type, 0 );
// QgsDebugMsg( QString( "value=%1" ).arg( value ) );
QString v;

if ( mValidNoDataValue && ( fabs( value - mNoDataValue[i-1] ) <= TINY_VALUE || value != value ) )
{
v = tr( "null (no data)" );
}
else
{
v.setNum( value );
}

results[ i ] = v;

//CPLFree( data );
}
}

return true;
}

bool QgsGdalProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
{
// QgsDebugMsg( "Entered" );
Expand Down
2 changes: 2 additions & 0 deletions src/providers/gdal/qgsgdalprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class QgsGdalProvider : public QgsRasterDataProvider
/** \brief Identify raster value(s) found on the point position */
bool identify( const QgsPoint & point, QMap<QString, QString>& results );

bool identify( const QgsPoint & point, QMap<int, QString>& results );

/**
* \brief Identify details from a GDAL layer from the last screen update
*
Expand Down