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

Fix identified coordinates when project crs differs from 3d view's crs #59265

Merged
merged 2 commits into from
Nov 8, 2024
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
28 changes: 19 additions & 9 deletions src/app/3d/qgs3dmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
QgsMapToolIdentifyAction *identifyTool2D = QgisApp::instance()->identifyMapTool();
identifyTool2D->clearResults();

QgsMapCanvas *canvas2D = identifyTool2D->canvas();
const QgsCoordinateTransform ct( mCanvas->mapSettings()->crs(), canvas2D->mapSettings().destinationCrs(), canvas2D->mapSettings().transformContext() );

bool showTerrainResults = true;

for ( auto it = allHits.constKeyValueBegin(); it != allHits.constKeyValueEnd(); ++it )
Expand All @@ -78,7 +81,18 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
{
const QgsRayCastingUtils::RayHit hit = it->second.first();
const QgsVector3D mapCoords = Qgs3DUtils::worldToMapCoordinates( hit.pos, mCanvas->mapSettings()->origin() );
const QgsPoint pt( mapCoords.x(), mapCoords.y(), mapCoords.z() );
QgsVector3D mapCoordsCanvas2D;
try
{
mapCoordsCanvas2D = ct.transform( mapCoords );
}
catch ( QgsCsException &e )
{
Q_UNUSED( e )
nyalldawson marked this conversation as resolved.
Show resolved Hide resolved
QgsDebugError( QStringLiteral( "Could not transform identified coordinates to project crs: %1" ).arg( e.what() ) );
}

const QgsPoint pt( mapCoordsCanvas2D.x(), mapCoordsCanvas2D.y(), mapCoordsCanvas2D.z() );
identifyTool2D->showResultsForFeature( vlayer, hit.fid, pt );
showTerrainResults = false;
}
Expand All @@ -105,7 +119,7 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
QgsCoordinateUtils::formatCoordinatePartsForProject(
QgsProject::instance(),
QgsPointXY( mapCoords.x(), mapCoords.y() ),
QgsProject::instance()->crs(),
mCanvas->mapSettings()->crs(),
6, x, y
);

Expand Down Expand Up @@ -139,14 +153,10 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
const double searchRadiusPx = searchRadiusMM * pixelsPerMM;
const double searchRadiusMapUnits = scene->worldSpaceError( searchRadiusPx, hit.distance );

QgsMapCanvas *canvas2D = identifyTool2D->canvas();

// transform the point and search radius to CRS of the map canvas (if they are different)
const QgsCoordinateTransform ct( mCanvas->mapSettings()->crs(), canvas2D->mapSettings().destinationCrs(), canvas2D->mapSettings().transformContext() );

const QgsVector3D mapCoords = Qgs3DUtils::worldToMapCoordinates( hit.pos, mCanvas->mapSettings()->origin() );
const QgsPointXY mapPoint( mapCoords.x(), mapCoords.y() );

// transform the point and search radius to CRS of the map canvas (if they are different)
QgsPointXY mapPointCanvas2D = mapPoint;
double searchRadiusCanvas2D = searchRadiusMapUnits;
try
Expand All @@ -156,10 +166,10 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
const QgsPointXY mapPointSearchRadiusCanvas2D = ct.transform( mapPointSearchRadius );
searchRadiusCanvas2D = mapPointCanvas2D.distance( mapPointSearchRadiusCanvas2D );
}
catch ( QgsException &e )
catch ( QgsCsException &e )
{
Q_UNUSED( e )
QgsDebugError( QStringLiteral( "Caught exception %1" ).arg( e.what() ) );
QgsDebugError( QStringLiteral( "Could not transform identified coordinates to project crs: %1" ).arg( e.what() ) );
}

identifyTool2D->identifyAndShowResults( QgsGeometry::fromPointXY( mapPointCanvas2D ), searchRadiusCanvas2D );
Expand Down
Loading