mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-07 00:15:48 -04:00
make 3D identify results simular to 2D
This commit is contained in:
parent
d67bd5ad00
commit
f85d551d2c
@ -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 );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user