Skip to content
Permalink
Browse files

unify 2D and 3D identify results conversion

  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Jan 13, 2021
1 parent 59bb58f commit f363877dfaf2c39b2b6cc195c21e038f8fc84354
@@ -128,6 +128,17 @@ Performs identification based on a geometry (in map coordinates)
%Docstring
Returns a pointer to the identify menu which will be used in layer selection mode
this menu can also be customized
%End

static void fromPointCloudIdentificationToIdentifyResults( QgsPointCloudLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results );
%Docstring
Converts point cloud identification results from variant maps to QgsMapToolIdentify.IdentifyResult and apply some formatting

.. note::

: the converted variant maps are pushed at the back of ``results`` without cleaning what's in it previously

.. versionadded:: 3.18
%End

public slots:
@@ -256,9 +256,7 @@ void Qgs3DMapCanvas::updateTemporalRange( const QgsDateTimeRange &temporalrange
mScene->updateTemporal();
}

void Qgs3DMapCanvas::identifyPointCloudOnMouseEvent( QVector<QPair<QgsMapLayer *, QVector<QVariantMap>>> &result, QMouseEvent *event )
QSize Qgs3DMapCanvas::windowSize() const
{
QgsRay3D ray = Qgs3DUtils::rayFromScreenPoint( event->pos(), mEngine->size(), mEngine->camera() );

mScene->identifyPointCloudOnRay( result, ray );
return mEngine->size();
}
@@ -87,11 +87,11 @@ class Qgs3DMapCanvas : public QWidget
void setTemporalController( QgsTemporalController *temporalController );

/**
* Identifies point cloud using mouse event
* Returns the size of the 3D canvas window
*
* \since QGIS 3.18
*/
void identifyPointCloudOnMouseEvent( QVector<QPair<QgsMapLayer *, QVector<QVariantMap>>> &result, QMouseEvent *event );
QSize windowSize() const;

signals:
//! Emitted when the 3D map canvas was successfully saved as image
@@ -34,6 +34,8 @@
#include "qgspointcloudlayerelevationproperties.h"

#include "qgs3dmapscenepickhandler.h"
#include "qgs3dutils.h"
#include "qgscameracontroller.h"

class Qgs3DMapToolIdentifyPickHandler : public Qgs3DMapScenePickHandler
{
@@ -88,41 +90,16 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )

// point cloud identification
QVector<QPair<QgsMapLayer *, QVector<QVariantMap>>> layerPoints;
canvas()->identifyPointCloudOnMouseEvent( layerPoints, event );
Qgs3DMapCanvas *canvas = this->canvas();

QgsRay3D ray = Qgs3DUtils::rayFromScreenPoint( event->pos(), canvas->windowSize(), canvas->cameraController()->camera() );
canvas->scene()->identifyPointCloudOnRay( layerPoints, ray );

QVector<QgsMapToolIdentify::IdentifyResult> identifyResults;
QList<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;
}
QgsMapToolIdentify::fromPointCloudIdentificationToIdentifyResults( pcLayer, layerPoints[i].second, identifyResults );
}

QgsMapToolIdentifyAction *identifyTool2D = QgisApp::instance()->identifyMapTool();
@@ -273,7 +273,7 @@ void QgsMapToolIdentifyAction::keyReleaseEvent( QKeyEvent *e )
}


void QgsMapToolIdentifyAction::showIdentifyResults( const QVector<IdentifyResult> &identifyResults )
void QgsMapToolIdentifyAction::showIdentifyResults( const QList<IdentifyResult> &identifyResults )
{
for ( const IdentifyResult &res : identifyResults )
{
@@ -68,8 +68,12 @@ 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 );
//! Shows identification results in the GUI
void showIdentifyResults( const QVector<IdentifyResult> &identifyResults );

/**
* Shows identification results in the GUI
* \since QGIS 3.18
*/
void showIdentifyResults( const QList<IdentifyResult> &identifyResults );
public slots:
void handleCopyToClipboard( QgsFeatureStore & );
void handleChangedRasterResults( QList<QgsMapToolIdentify::IdentifyResult> &results );
@@ -516,35 +516,9 @@ bool QgsMapToolIdentify::identifyPointCloudLayer( QList<QgsMapToolIdentify::Iden
const double searchRadiusMapUnits = mOverrideCanvasSearchRadius < 0 ? searchRadiusMU( mCanvas ) : mOverrideCanvasSearchRadius;

const QVector<QVariantMap> points = renderer->identify( layer, context, geometry, searchRadiusMapUnits );
int id = 1;
const QgsPointCloudLayerElevationProperties *elevationProps = qobject_cast< const QgsPointCloudLayerElevationProperties *>( layer->elevationProperties() );
for ( const QVariantMap &pt : points )
{
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)" ).arg( attrIt.value().toString(), classification );
}
else
{
ptStr[attrIt.key()] = attrIt.value().toString();
}
}
QgsMapToolIdentify::IdentifyResult res( layer, classification.isEmpty() ? QString::number( id ) : QStringLiteral( "%1 (%2)" ).arg( id ).arg( classification ), ptStr, QMap<QString, QString>() );
results->append( res );
++id;
}

fromPointCloudIdentificationToIdentifyResults( layer, points, *results );

return true;
}

@@ -1197,3 +1171,36 @@ void QgsMapToolIdentify::formatChanged( QgsRasterLayer *layer )
emit changedRasterResults( results );
}
}

void QgsMapToolIdentify::fromPointCloudIdentificationToIdentifyResults( QgsPointCloudLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results )
{
int id = 1;
const QgsPointCloudLayerElevationProperties *elevationProps = qobject_cast< const QgsPointCloudLayerElevationProperties *>( layer->elevationProperties() );
for ( const QVariantMap &pt : identified )
{
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)" ).arg( attrIt.value().toString(), classification );
}
else
{
ptStr[attrIt.key()] = attrIt.value().toString();
}
}
QgsMapToolIdentify::IdentifyResult res( layer, classification.isEmpty() ? QString::number( id ) : QStringLiteral( "%1 (%2)" ).arg( id ).arg( classification ), ptStr, QMap<QString, QString>() );
results.append( res );
++id;
}
}
@@ -36,6 +36,7 @@ class QgsMeshLayer;
class QgsHighlight;
class QgsIdentifyMenu;
class QgsPointCloudLayer;
class QgsPointCloudLayerElevationProperties;

/**
* \ingroup gui
@@ -146,6 +147,13 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
*/
QgsIdentifyMenu *identifyMenu() { return mIdentifyMenu; }

/**
* Converts point cloud identification results from variant maps to QgsMapToolIdentify::IdentifyResult and apply some formatting
* \note : the converted variant maps are pushed at the back of \a results without cleaning what's in it previously
* \since QGIS 3.18
*/
static void fromPointCloudIdentificationToIdentifyResults( QgsPointCloudLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results );

public slots:
void formatChanged( QgsRasterLayer *layer );

0 comments on commit f363877

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