Skip to content

Commit

Permalink
make 3D identify results simular to 2D
Browse files Browse the repository at this point in the history
  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Jan 13, 2021
1 parent d67bd5a commit f85d551
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
38 changes: 37 additions & 1 deletion src/app/3d/qgs3dmaptoolidentify.cpp
Expand Up @@ -31,6 +31,7 @@
#include <Qt3DRender/QPickEvent>

#include "qgspointcloudlayer.h"
#include "qgspointcloudlayerelevationproperties.h"

#include "qgs3dmapscenepickhandler.h"

Expand Down Expand Up @@ -89,8 +90,43 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
QVector<QPair<QgsMapLayer *, QVector<QVariantMap>>> layerPoints;
canvas()->identifyPointCloudOnMouseEvent( layerPoints, event );

QVector<QgsMapToolIdentify::IdentifyResult> identifyResults;
for ( int i = 0; i < layerPoints.size(); ++i )
{
QgsPointCloudLayer *pcLayer = dynamic_cast< QgsPointCloudLayer * >( layerPoints[i].first );
int id = 1;
const QgsPointCloudLayerElevationProperties *elevationProps = qobject_cast< const QgsPointCloudLayerElevationProperties *>( pcLayer->elevationProperties() );
for ( const QVariantMap &pt : layerPoints[i].second )
{
QMap<QString, QString> ptStr;
QString classification;
for ( auto attrIt = pt.constBegin(); attrIt != pt.constEnd(); ++attrIt )
{
if ( attrIt.key().compare( QLatin1String( "Z" ), Qt::CaseInsensitive ) == 0
&& ( !qgsDoubleNear( elevationProps->zScale(), 1 ) || !qgsDoubleNear( elevationProps->zOffset(), 0 ) ) )
{
// Apply elevation properties
ptStr[ tr( "Z (original)" ) ] = attrIt.value().toString();
ptStr[ tr( "Z (adjusted)" ) ] = QString::number( attrIt.value().toDouble() * elevationProps->zScale() + elevationProps->zOffset() );
}
else if ( attrIt.key().compare( QLatin1String( "Classification" ), Qt::CaseInsensitive ) == 0 )
{
classification = QgsPointCloudDataProvider::translatedLasClassificationCodes().value( attrIt.value().toInt() );
ptStr[ attrIt.key() ] = QStringLiteral( "%1_%2 (%3)" ).arg( pcLayer->name() ).arg( attrIt.value().toString(), classification );
}
else
{
ptStr[attrIt.key()] = attrIt.value().toString();
}
}
QgsMapToolIdentify::IdentifyResult res( pcLayer, classification.isEmpty() ? QString::number( id ) : QStringLiteral( "%1 (%2)" ).arg( id ).arg( classification ), ptStr, QMap<QString, QString>() );
identifyResults.append( res );
++id;
}
}

QgsMapToolIdentifyAction *identifyTool2D = QgisApp::instance()->identifyMapTool();
identifyTool2D->showPointCloudIdentifyResults( layerPoints );
identifyTool2D->showIdentifyResults( identifyResults );
}

void Qgs3DMapToolIdentify::activate()
Expand Down
16 changes: 4 additions & 12 deletions src/app/qgsmaptoolidentifyaction.cpp
Expand Up @@ -272,20 +272,12 @@ void QgsMapToolIdentifyAction::keyReleaseEvent( QKeyEvent *e )
QgsMapTool::keyReleaseEvent( e );
}

void QgsMapToolIdentifyAction::showPointCloudIdentifyResults( const QVector<QPair<QgsMapLayer *, QVector<QVariantMap>>> &layersAndPoints )

void QgsMapToolIdentifyAction::showIdentifyResults( const QVector<IdentifyResult> &identifyResults )
{
for ( int i = 0; i < layersAndPoints.size(); ++i )
for ( const IdentifyResult &res : identifyResults )
{
QgsMapLayer *layer = layersAndPoints[i].first;
int id = 0;
for ( const QVariantMap &pt : layersAndPoints[i].second )
{
QMap<QString, QString> strMap;
for ( QString key : pt.keys() )
strMap[ key ] = pt[ key ].toString();
resultsDialog()->addFeature( IdentifyResult( layer, QString( "%1_%2" ).arg( layer->name() ).arg( id ), strMap, strMap ) );
++id;
}
resultsDialog()->addFeature( res );
}
resultsDialog()->show();
// update possible view modes
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolidentifyaction.h
Expand Up @@ -68,8 +68,8 @@ class APP_EXPORT QgsMapToolIdentifyAction : public QgsMapToolIdentify
void clearResults();
//! Looks up feature by its ID and outputs the result in GUI
void showResultsForFeature( QgsVectorLayer *vlayer, QgsFeatureId fid, const QgsPoint &pt );

void showPointCloudIdentifyResults( const QVector<QPair<QgsMapLayer *, QVector<QVariantMap>>> &layersAndPoints );
//! Shows identification results in the GUI
void showIdentifyResults( const QVector<IdentifyResult> &identifyResults );
public slots:
void handleCopyToClipboard( QgsFeatureStore & );
void handleChangedRasterResults( QList<QgsMapToolIdentify::IdentifyResult> &results );
Expand Down
1 change: 1 addition & 0 deletions src/core/pointcloud/qgspointclouddataprovider.cpp
Expand Up @@ -464,6 +464,7 @@ QVector<QVariantMap> QgsPointCloudDataProvider::getPointsOnRay( const QVector3D
pointAttr[ QStringLiteral( "X" ) ] = x;
pointAttr[ QStringLiteral( "Y" ) ] = y;
pointAttr[ QStringLiteral( "Z" ) ] = z;
pointAttr[ QStringLiteral( "Distance to camera" ) ] = ( point - rayOrigin ).length();
points.push_back( pointAttr );
}
}
Expand Down

0 comments on commit f85d551

Please sign in to comment.