From 365229eb1b31ff477475e5769d4937c653b9af6c Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 11 Sep 2023 10:49:19 +1000 Subject: [PATCH] Show a highlight on identified raster pixels when using identify tool Matches the vector/vector tile/point cloud behaviour of showing the geometry of the identified result in the canvas Very handy when a identifying a raster which has sections of similar colored pixels and it's difficult to visually determine the exact extent of a pixel. --- src/gui/qgsmaptoolidentify.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/gui/qgsmaptoolidentify.cpp b/src/gui/qgsmaptoolidentify.cpp index 9939e6f54d14..40874c1a5562 100644 --- a/src/gui/qgsmaptoolidentify.cpp +++ b/src/gui/qgsmaptoolidentify.cpp @@ -1064,6 +1064,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList *results, Qg const double xres = layer->rasterUnitsPerPixelX(); const double yres = layer->rasterUnitsPerPixelY(); + QgsRectangle pixelRect; // Don't derive clicked column/row for providers that serve dynamically rendered map images if ( ( dprovider->capabilities() & QgsRasterDataProvider::Size ) && !qgsDoubleNear( xres, 0 ) && !qgsDoubleNear( yres, 0 ) ) { @@ -1075,12 +1076,16 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList *results, Qg derivedAttributes.insert( tr( "Column (0-based)" ), QLocale().toString( rasterCol ) ); derivedAttributes.insert( tr( "Row (0-based)" ), QLocale().toString( rasterRow ) ); + + pixelRect = QgsRectangle( rasterCol * xres + extent.xMinimum(), + extent.yMaximum() - ( rasterRow + 1 ) * yres, + ( rasterCol + 1 ) * xres + extent.xMinimum(), + extent.yMaximum() - ( rasterRow * yres ) ); } if ( identifyResult.isValid() ) { QMap values = identifyResult.results(); - QgsGeometry geometry; if ( format == Qgis::RasterIdentifyFormat::Value ) { for ( auto it = values.constBegin(); it != values.constEnd(); ++it ) @@ -1152,7 +1157,15 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList *results, Qg } QString label = layer->name(); - results->append( IdentifyResult( qobject_cast( layer ), label, attributes, derivedAttributes ) ); + QgsFeature feature; + if ( !pixelRect.isNull() ) + { + feature.setGeometry( QgsGeometry::fromRect( pixelRect ) ); + } + + IdentifyResult result( qobject_cast( layer ), label, QgsFields(), feature, derivedAttributes ); + result.mAttributes = attributes; + results->append( result ); } else if ( format == Qgis::RasterIdentifyFormat::Feature ) {