Skip to content
Permalink
Browse files

make single click identify work

  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 4, 2021
1 parent d40a9b7 commit ef9d2727a69b131fd87feac8b9eb99616a65cdce
@@ -56,12 +56,6 @@ Ctor

~QgsPointCloudDataProvider();

QVector<QMap<QString, QVariant>> identify( QgsPointCloudLayer *layer, float maximumError, float rootErrorPixels, QgsGeometry extentGeometry, const QgsDoubleRange extentZRange );
%Docstring
Returns the list of points of the point cloud layer ``layer`` according to a zoom level
defined by ``maximumError`` and ``rootErrorPixels``, and an extent defined by a geometry
in the 2D plane ``geometry`` and a range for z values ``extentZRange``
%End

virtual QgsPointCloudDataProvider::Capabilities capabilities() const;
%Docstring
@@ -82,7 +82,7 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
* defined by \a maximumError and \a rootErrorPixels, and an extent defined by a geometry
* in the 2D plane \a geometry and a range for z values \a extentZRange
*/
QVector<QMap<QString, QVariant>> identify( QgsPointCloudLayer *layer, float maximumError, float rootErrorPixels, QgsGeometry extentGeometry, const QgsDoubleRange extentZRange );
QVector<QMap<QString, QVariant>> identify( QgsPointCloudLayer *layer, float maximumError, float rootErrorPixels, QgsGeometry extentGeometry, const QgsDoubleRange extentZRange ) SIP_SKIP;

/**
* Returns flags containing the supported capabilities for the data provider.
@@ -23,6 +23,7 @@
#include "qgspointcloudindex.h"
#include "qgspointcloudlayerelevationproperties.h"
#include "qgslogger.h"
#include "qgscircle.h"

QgsPointCloudRenderContext::QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset, double zValueScale, double zValueFixedOffset )
: mRenderContext( context )
@@ -228,7 +229,38 @@ QVector<QMap<QString, QVariant>> QgsPointCloudRenderer::identify( QgsPointCloudL

float rootErrorPixels = rootErrorInMapCoordinates / mapUnitsPerPixel; // in pixels

QVector<QMap<QString, QVariant>> points = layer->dataProvider()->identify( layer, maximumError, rootErrorPixels, geometry, QgsDoubleRange() );
QgsGeometry selectionGeometry = geometry;
if ( geometry.type() == QgsWkbTypes::PointGeometry )
{
double x = geometry.asPoint().x();
double y = geometry.asPoint().y();
if ( pointSymbol() == QgsPointCloudRenderer::PointSymbol::Square )
{
QgsPointXY deviceCoords = context.renderContext().mapToPixel().transform( QgsPointXY( x, y ) );
QgsPointXY point1( deviceCoords.x() - 2 * pointSize(), deviceCoords.y() - 2 * pointSize() );
QgsPointXY point2( deviceCoords.x() + 2 * pointSize(), deviceCoords.y() + 2 * pointSize() );
QgsPointXY point1MapCoords = context.renderContext().mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = context.renderContext().mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsRectangle pointRect( point1MapCoords, point2MapCoords );
selectionGeometry = QgsGeometry::fromRect( pointRect );
}
else if ( pointSymbol() == QgsPointCloudRenderer::PointSymbol::Circle )
{
QgsPoint centerMapCoords( x, y );
QgsPointXY deviceCoords = context.renderContext().mapToPixel().transform( centerMapCoords );
QgsPoint point1( deviceCoords.x(), deviceCoords.y() - 2 * pointSize() );
QgsPoint point2( deviceCoords.x(), deviceCoords.y() + 2 * pointSize() );
QgsPointXY point1MapCoords = context.renderContext().mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = context.renderContext().mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsCircle circle = QgsCircle::from2Points( QgsPoint( point1MapCoords ), QgsPoint( point2MapCoords ) );
// TODO: make this faster?
QgsPolygon *polygon = circle.toPolygon( 5 );
QgsGeometry circleGeometry( polygon );
selectionGeometry = circleGeometry;
}
}

QVector<QMap<QString, QVariant>> points = layer->dataProvider()->identify( layer, maximumError, rootErrorPixels, selectionGeometry, QgsDoubleRange() );

for ( QMap<QString, QVariant> point : points )
{
@@ -509,13 +509,14 @@ bool QgsMapToolIdentify::identifyPointCloudLayer( QList<QgsMapToolIdentify::Iden
{
Q_UNUSED( identifyContext );
QgsCoordinateTransform ct( mCanvas->mapSettings().destinationCrs(), layer->crs(), mCanvas->mapSettings().transformContext() );
QgsPointCloudRenderer *renderer = layer->renderer();

QgsGeometry transformedGeometry = geometry;

if ( ct.isValid() )
transformedGeometry.transform( ct );

QgsRenderContext context = QgsRenderContext::fromMapSettings( mCanvas->mapSettings() );
QgsPointCloudRenderer *renderer = layer->renderer();
QVector<QMap<QString, QVariant>> points = renderer->identify( layer, context, transformedGeometry );
int id = 0;
for ( QMap<QString, QVariant> pt : points )

0 comments on commit ef9d272

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