Skip to content
Permalink
Browse files

make 3D identify results simular to 2D

  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Jan 13, 2021
1 parent d67bd5a commit f85d551d2cec228ce677cf919a8bfee4c1a76670
@@ -31,6 +31,7 @@
#include <Qt3DRender/QPickEvent>

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

#include "qgs3dmapscenepickhandler.h"

@@ -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()
@@ -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
@@ -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 );
@@ -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 );
}
}

0 comments on commit f85d551

Please sign in to comment.
You can’t perform that action at this time.