44 changes: 21 additions & 23 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )

QgsGdalProviderBase::registerGdalDrivers();

// GDAL tends to open AAIGrid as Float32 which results in lost precision
// and confusing values shown to users, force Float64
CPLSetConfigOption( "AAIGRID_DATATYPE", "Float64" );

// To get buildSupportedRasterFileFilter the provider is called with empty uri
if ( uri.isEmpty() )
{
Expand Down Expand Up @@ -816,15 +820,18 @@ 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 )
QMap<int, void *> QgsGdalProvider::identify( const QgsPoint & point )
{
// QgsDebugMsg( "Entered" );
QgsDebugMsg( "Entered" );
QMap<int, void *> results;
if ( !mExtent.contains( point ) )
{
// Outside the raster
for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
{
results[ i ] = tr( "out of extent" );
void * data = VSIMalloc( dataTypeSize( i ) / 8 );
writeValue( data, dataType( i ), 0, noDataValue() );
results.insert( i, data );
}
}
else
Expand All @@ -845,7 +852,6 @@ bool QgsGdalProvider::identify( const QgsPoint & point, QMap<int, QString>& resu
for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
{
GDALRasterBandH gdalBand = GDALGetRasterBand( mGdalDataset, i );
double data[4];

int r = 0;
int c = 0;
Expand All @@ -872,38 +878,29 @@ bool QgsGdalProvider::identify( const QgsPoint & point, QMap<int, QString>& resu
}
}
#endif
int typeSize = dataTypeSize( i ) / 8;
void * tmpData = VSIMalloc( typeSize * width * height );

CPLErr err = GDALRasterIO( gdalBand, GF_Read, col, row, width, height,
data, width, height, GDT_Float64, 0, 0 );
tmpData, width, height,
( GDALDataType ) mGdalDataType[i-1], 0, 0 );

if ( err != CPLE_None )
{
QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
}
double value = data[r*2+c];
void * data = VSIMalloc( typeSize );
memcpy( data, ( void* )(( char* )tmpData + ( r*width + c )*typeSize ), typeSize );
results.insert( i, data );

//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 );
CPLFree( tmpData );
}
}

return true;
return results;
}

#if 0
bool QgsGdalProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
{
QMap<int, QString> results;
Expand All @@ -914,6 +911,7 @@ bool QgsGdalProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>
}
return true;
}
#endif

int QgsGdalProvider::capabilities() const
{
Expand Down
6 changes: 4 additions & 2 deletions src/providers/gdal/qgsgdalprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
bool isValid();

/** \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<QString, QString>& results );

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

QMap<int, void *> identify( const QgsPoint & point );

/**
* \brief Identify details from a GDAL layer from the last screen update
Expand Down
36 changes: 23 additions & 13 deletions src/providers/grass/qgsgrassrasterprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,25 +364,35 @@ int QgsGrassRasterProvider::yBlockSize() const
int QgsGrassRasterProvider::xSize() const { return mCols; }
int QgsGrassRasterProvider::ySize() const { return mRows; }

bool QgsGrassRasterProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
QMap<int, void *> QgsGrassRasterProvider::identify( const QgsPoint & thePoint )
{
QgsDebugMsg( "Entered" );
//theResults["Error"] = tr( "Out of extent" );
QMap<int, void *> results;

// TODO: use doubles instead of strings
//theResults = QgsGrass::query( mGisdbase, mLocation, mMapset, mMapName, QgsGrass::Raster, thePoint.x(), thePoint.y() );
QString value = mRasterValue.value( thePoint.x(), thePoint.y() );
theResults.clear();
QString strValue = mRasterValue.value( thePoint.x(), thePoint.y() );
// attention, value tool does his own tricks with grass identify() so it stops to refresh values outside extent or null values e.g.
if ( value == "out" )
{
value = tr( "Out of extent" );
}
if ( value == "null" )

double value = noDataValue();

if ( strValue != "out" && strValue != "null" )
{
value = tr( "null (no data)" );
bool ok;
value = strValue.toDouble( & ok );
if ( !ok )
{
value = 999999999;
QgsDebugMsg( "Cannot convert string to double" );
}
}
theResults["value"] = value;
QgsDebugMsg( "value = " + value );
return true;
void * data = malloc( dataTypeSize( 1 ) / 8 );
writeValue( data, dataType( 1 ), 0, value );

results.insert( 1, data );
QgsDebugMsg( "strValue = " + strValue );

return results;
}

int QgsGrassRasterProvider::capabilities() const
Expand Down
3 changes: 2 additions & 1 deletion src/providers/grass/qgsgrassrasterprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
bool isValid();

/** \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<QString, QString>& results );
QMap<int, void *> identify( const QgsPoint & thePoint );

/**
* \brief Identify details from a GRASS layer from the last screen update
Expand Down
31 changes: 11 additions & 20 deletions src/providers/wcs/qgswcsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,19 +1503,21 @@ QString QgsWcsProvider:: htmlRow( const QString &text1, const QString &text2 )
return "<tr>" + htmlCell( text1 ) + htmlCell( text2 ) + "</tr>";
}

bool QgsWcsProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
QMap<int, void *> QgsWcsProvider::identify( const QgsPoint & thePoint )
{
QgsDebugMsg( "Entered" );
theResults.clear();
QMap<int, void *> results;

if ( !extent().contains( thePoint ) )
{
// Outside the raster
for ( int i = 1; i <= bandCount(); i++ )
{
theResults[ generateBandName( i )] = tr( "out of extent" );
void * data = VSIMalloc( dataTypeSize( i ) / 8 );
writeValue( data, dataType( i ), 0, noDataValue() );
results.insert( i, data );
}
return true;
return results;
}

// It would be nice to use last cached block if possible, unfortunately we don't know
Expand Down Expand Up @@ -1556,7 +1558,7 @@ bool QgsWcsProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>&
if ( !mCachedGdalDataset ||
!mCachedViewExtent.contains( thePoint ) )
{
return false; // should not happen
return results; // should not happen
}

double x = thePoint.x();
Expand All @@ -1575,31 +1577,20 @@ bool QgsWcsProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>&
for ( int i = 1; i <= GDALGetRasterCount( mCachedGdalDataset ); i++ )
{
GDALRasterBandH gdalBand = GDALGetRasterBand( mCachedGdalDataset, i );
double value;

void * data = VSIMalloc( dataTypeSize( i ) / 8 );
CPLErr err = GDALRasterIO( gdalBand, GF_Read, col, row, 1, 1,
&value, 1, 1, GDT_Float64, 0, 0 );
data, 1, 1, ( GDALDataType ) mGdalDataType[i-1], 0, 0 );

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

QString v;

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

theResults[ generateBandName( i )] = v;
results.insert( i, data );
}

return true;
return results;
}

QString QgsWcsProvider::identifyAsText( const QgsPoint &point )
Expand Down
3 changes: 2 additions & 1 deletion src/providers/wcs/qgswcsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
int xSize() const;
int ySize() const;
QString metadata();
bool identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults );
//bool identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults );
QMap<int, void *> identify( const QgsPoint & thePoint );
QString identifyAsHtml( const QgsPoint& point );
QString identifyAsText( const QgsPoint& point );
QString lastErrorTitle();
Expand Down