Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show a highlight on identified raster pixels when using identify tool #54541

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/gui/qgsmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *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 ) )
{
Expand All @@ -1075,12 +1076,16 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *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<int, QVariant> values = identifyResult.results();
QgsGeometry geometry;
if ( format == Qgis::RasterIdentifyFormat::Value )
{
for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
Expand Down Expand Up @@ -1152,7 +1157,15 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
}

QString label = layer->name();
results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
QgsFeature feature;
if ( !pixelRect.isNull() )
{
feature.setGeometry( QgsGeometry::fromRect( pixelRect ) );
}

IdentifyResult result( qobject_cast<QgsMapLayer *>( layer ), label, QgsFields(), feature, derivedAttributes );
result.mAttributes = attributes;
results->append( result );
}
else if ( format == Qgis::RasterIdentifyFormat::Feature )
{
Expand Down
Loading