@@ -301,48 +301,21 @@ QgsRasterIdentifyResult QgsRasterDataProvider::identify( const QgsPointXY &point
301301}
302302
303303double QgsRasterDataProvider::sample ( const QgsPointXY &point, int band,
304- bool *ok, const QgsRectangle &boundingBox, int width, int height, int )
304+ bool *ok, const QgsRectangle &boundingBox, int width, int height, int dpi )
305305{
306306 if ( ok )
307307 *ok = false ;
308308
309- if ( !extent ().contains ( point ) )
310- {
311- // Outside the raster
312- return std::numeric_limits<double >::quiet_NaN ();
313- }
314-
315- QgsRectangle finalExtent = boundingBox;
316- if ( finalExtent.isEmpty () )
317- finalExtent = extent ();
318-
319- if ( width == 0 )
320- {
321- width = capabilities () & Size ? xSize () : 1000 ;
322- }
323- if ( height == 0 )
324- {
325- height = capabilities () & Size ? ySize () : 1000 ;
326- }
327-
328- // Calculate the row / column where the point falls
329- double xres = ( finalExtent.width () ) / width;
330- double yres = ( finalExtent.height () ) / height;
331-
332- int col = static_cast < int >( std::floor ( ( point.x () - finalExtent.xMinimum () ) / xres ) );
333- int row = static_cast < int >( std::floor ( ( finalExtent.yMaximum () - point.y () ) / yres ) );
309+ const auto res = identify ( point, QgsRaster::IdentifyFormatValue, boundingBox, width, height, dpi );
310+ const QVariant value = res.results ().value ( band );
334311
335- double xMin = finalExtent.xMinimum () + col * xres;
336- double xMax = xMin + xres;
337- double yMax = finalExtent.yMaximum () - row * yres;
338- double yMin = yMax - yres;
339- QgsRectangle pixelExtent ( xMin, yMin, xMax, yMax );
312+ if ( !value.isValid () )
313+ return std::numeric_limits<double >::quiet_NaN ();
340314
341- std::unique_ptr< QgsRasterBlock > bandBlock ( block ( band, pixelExtent, 1 , 1 ) );
342- if ( bandBlock && ok )
315+ if ( ok )
343316 *ok = true ;
344317
345- return bandBlock ? bandBlock-> value ( 0 ) : std::numeric_limits< double >:: quiet_NaN ( );
318+ return value. toDouble ( ok );
346319}
347320
348321QString QgsRasterDataProvider::lastErrorFormat ()
0 commit comments