Skip to content

Commit

Permalink
qgsmaptoolidentify: Display index for mesh data
Browse files Browse the repository at this point in the history
This is achieved by using `QgsMeshLayer::closestElement()` instead of
`QgsMeshLayer::snapOnElement()`.
  • Loading branch information
ptitjano committed Mar 7, 2025
1 parent 62f2132 commit d595836
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/gui/maptools/qgsmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,23 +391,29 @@ bool QgsMapToolIdentify::identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyRe

QMap<QString, QString> derivedGeometry;

QgsPointXY vertexPoint = layer->snapOnElement( QgsMesh::Vertex, point, searchRadius );
QgsPointXY vertexPoint;
const int vertexId = layer->closestElement( QgsMesh::Vertex, point, searchRadius, vertexPoint );
if ( !vertexPoint.isEmpty() )
{
derivedGeometry.insert( tr( "Snapped Vertex Index" ), QLocale().toString( vertexId ) );
derivedGeometry.insert( tr( "Snapped Vertex Position X" ), QLocale().toString( vertexPoint.x() ) );
derivedGeometry.insert( tr( "Snapped Vertex Position Y" ), QLocale().toString( vertexPoint.y() ) );
}

QgsPointXY faceCentroid = layer->snapOnElement( QgsMesh::Face, point, searchRadius );
QgsPointXY faceCentroid;
const int faceId = layer->closestElement( QgsMesh::Face, point, searchRadius, faceCentroid );
if ( !faceCentroid.isEmpty() )
{
derivedGeometry.insert( tr( "Face Index" ), QLocale().toString( faceId ) );
derivedGeometry.insert( tr( "Face Centroid X" ), QLocale().toString( faceCentroid.x() ) );
derivedGeometry.insert( tr( "Face Centroid Y" ), QLocale().toString( faceCentroid.y() ) );
}

QgsPointXY pointOnEdge = layer->snapOnElement( QgsMesh::Edge, point, searchRadius );
QgsPointXY pointOnEdge;
const int edgeId = layer->closestElement( QgsMesh::Edge, point, searchRadius, pointOnEdge );
if ( !pointOnEdge.isEmpty() )
{
derivedGeometry.insert( tr( "Edge Index" ), QLocale().toString( edgeId ) );
derivedGeometry.insert( tr( "Point on Edge X" ), QLocale().toString( pointOnEdge.x() ) );
derivedGeometry.insert( tr( "Point on Edge Y" ), QLocale().toString( pointOnEdge.y() ) );
}
Expand Down

0 comments on commit d595836

Please sign in to comment.