Skip to content
Permalink
Browse files

Fix picking of transparent pixels

  • Loading branch information
mhugent committed Jul 1, 2012
1 parent fa292eb commit 3deef8b28acfb5b67b4396f79064645ceac6dbc7
@@ -1315,44 +1315,42 @@ void QgsRasterLayerProperties::on_pbnRemoveSelectedRow_clicked()

void QgsRasterLayerProperties::pixelSelected( const QgsPoint& canvasPoint )
{
#if 0 //needs to be fixed
//PixelSelectorTool has registered a mouse click on the canvas, so bring the dialog back to the front
QgsRasterRenderer* renderer = mRendererWidget->renderer();
if ( !renderer )
{
return;
}

raise();
setModal( true );
activateWindow();

//Get the pixel values and add a new entry to the transparency table
if ( mMapCanvas && mPixelSelectorTool )
{
QMap< QString, QString > myPixelMap;
QMap< int, QString > myPixelMap;
mMapCanvas->unsetMapTool( mPixelSelectorTool );
mRasterLayer->identify( mMapCanvas->mapRenderer()->mapToLayerCoordinates( mRasterLayer, canvasPoint ), myPixelMap );
if ( tableTransparency->columnCount() == 2 )
{
QString myValue = myPixelMap[ mRasterLayer->grayBandName()];
if ( myValue != tr( "out of extent" ) )
{
tableTransparency->insertRow( tableTransparency->rowCount() );
tableTransparency->setItem( tableTransparency->rowCount() - 1, tableTransparency->columnCount() - 1, new QTableWidgetItem( "100.0" ) );
tableTransparency->setItem( tableTransparency->rowCount() - 1, 0, new QTableWidgetItem( myValue ) );
}
}
else

QList<int> bands = renderer->usesBands();
tableTransparency->insertRow( tableTransparency->rowCount() );
tableTransparency->setItem( tableTransparency->rowCount() - 1, tableTransparency->columnCount() - 1, new QTableWidgetItem( "100.0" ) );

for ( int i = 0; i < bands.size(); ++i )
{
QString myValue = myPixelMap[ mRasterLayer->redBandName()];
if ( myValue != tr( "out of extent" ) )
QMap< int, QString >::const_iterator pixelResult = myPixelMap.find( bands.at( i ) );
if ( pixelResult != myPixelMap.constEnd() )
{
tableTransparency->insertRow( tableTransparency->rowCount() );
tableTransparency->setItem( tableTransparency->rowCount() - 1, tableTransparency->columnCount() - 1, new QTableWidgetItem( "100.0" ) );
tableTransparency->setItem( tableTransparency->rowCount() - 1, 0, new QTableWidgetItem( myValue ) );
tableTransparency->setItem( tableTransparency->rowCount() - 1, 1, new QTableWidgetItem( myPixelMap[ mRasterLayer->greenBandName()] ) );
tableTransparency->setItem( tableTransparency->rowCount() - 1, 2, new QTableWidgetItem( myPixelMap[ mRasterLayer->blueBandName()] ) );
QString value = pixelResult.value();
if ( value != tr( "out of extent" ) )
{
tableTransparency->setItem( tableTransparency->rowCount() - 1, i, new QTableWidgetItem( value ) );
}
}
}
}
#else
Q_UNUSED( canvasPoint );
#endif //0

delete renderer;
}

void QgsRasterLayerProperties::sliderTransparency_valueChanged( int theValue )
@@ -184,6 +184,13 @@ bool QgsRasterDataProvider::identify( const QgsPoint& thePoint, QMap<QString, QS
return false;
}

bool QgsRasterDataProvider::identify( const QgsPoint & point, QMap<int, QString>& results )
{
Q_UNUSED( point );
results.clear();
return false;
}

QString QgsRasterDataProvider::lastErrorFormat()
{
return "text/plain";
@@ -390,6 +390,8 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
/** \brief Identify raster value(s) found on the point position */
virtual bool identify( const QgsPoint & point, QMap<QString, QString>& results );

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

/**
* \brief Identify details from a server (e.g. WMS) from the last screen update
*
@@ -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
*
@@ -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 );

@@ -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" );
@@ -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
*

0 comments on commit 3deef8b

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