// Default implementation for values QMap<int, QVariant> QgsRasterDataProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight ) { QgsDebugMsg( "Entered" ); QMap<int, QVariant> results; if ( theFormat != IdentifyFormatValue || !( capabilities() & IdentifyValue ) ) { QgsDebugMsg( "Format not supported" ); return results; } if ( !extent().contains( thePoint ) ) { // Outside the raster for ( int bandNo = 1; bandNo <= bandCount(); bandNo++ ) { results.insert( bandNo, noDataValue( bandNo ) ); } return results; } QgsRectangle myExtent = theExtent; if ( myExtent.isEmpty() ) myExtent = extent(); if ( theWidth == 0 ) { theWidth = capabilities() & Size ? xSize() : 1000; } if ( theHeight == 0 ) { theHeight = capabilities() & Size ? ySize() : 1000; } // Calculate the row / column where the point falls double xres = ( myExtent.width() ) / theWidth; double yres = ( myExtent.height() ) / theHeight; int col = ( int ) floor(( thePoint.x() - myExtent.xMinimum() ) / xres ); int row = ( int ) floor(( myExtent.yMaximum() - thePoint.y() ) / yres ); double xMin = myExtent.xMinimum() + col * xres; double xMax = xMin + xres; double yMax = myExtent.yMaximum() - row * yres; double yMin = yMax - yres; QgsRectangle pixelExtent( xMin, yMin, xMax, yMax ); for ( int i = 1; i <= bandCount(); i++ ) { QgsRasterBlock * myBlock = block( i, pixelExtent, 1, 1 ); double value = noDataValue( i ); if ( myBlock ) value = myBlock->value( 0 ); results.insert( i, value ); } return results; }
// Default implementation for values QgsRasterIdentifyResult QgsRasterDataProvider::identify( const QgsPointXY &point, QgsRaster::IdentifyFormat format, const QgsRectangle &boundingBox, int width, int height, int /*dpi*/ ) { QgsDebugMsgLevel( "Entered", 4 ); QMap<int, QVariant> results; if ( format != QgsRaster::IdentifyFormatValue || !( capabilities() & IdentifyValue ) ) { QgsDebugMsg( "Format not supported" ); return QgsRasterIdentifyResult( ERR( tr( "Format not supported" ) ) ); } if ( !extent().contains( point ) ) { // Outside the raster for ( int bandNo = 1; bandNo <= bandCount(); bandNo++ ) { results.insert( bandNo, QVariant() ); } return QgsRasterIdentifyResult( QgsRaster::IdentifyFormatValue, results ); } QgsRectangle finalExtent = boundingBox; if ( finalExtent.isEmpty() ) finalExtent = extent(); if ( width == 0 ) { width = capabilities() & Size ? xSize() : 1000; } if ( height == 0 ) { height = capabilities() & Size ? ySize() : 1000; } // Calculate the row / column where the point falls double xres = ( finalExtent.width() ) / width; double yres = ( finalExtent.height() ) / height; int col = static_cast< int >( std::floor( ( point.x() - finalExtent.xMinimum() ) / xres ) ); int row = static_cast< int >( std::floor( ( finalExtent.yMaximum() - point.y() ) / yres ) ); double xMin = finalExtent.xMinimum() + col * xres; double xMax = xMin + xres; double yMax = finalExtent.yMaximum() - row * yres; double yMin = yMax - yres; QgsRectangle pixelExtent( xMin, yMin, xMax, yMax ); for ( int i = 1; i <= bandCount(); i++ ) { QgsRasterBlock *myBlock = block( i, pixelExtent, 1, 1 ); if ( myBlock ) { double value = myBlock->value( 0 ); results.insert( i, value ); delete myBlock; } else { results.insert( i, QVariant() ); } } return QgsRasterIdentifyResult( QgsRaster::IdentifyFormatValue, results ); }