Skip to content
Permalink
Browse files

Add identify when rendering as circles

  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 4, 2021
1 parent 9358c9b commit 07512be37075da286c51ede6138ff0ddbf556766
Showing with 28 additions and 7 deletions.
  1. +28 −7 src/core/pointcloud/qgspointcloudlayerrenderer.cpp
@@ -30,6 +30,8 @@
#include "qgslogger.h"
#include "qgspointcloudlayerelevationproperties.h"
#include "qgsmessagelog.h"
#include "qgscircle.h"


QgsPointCloudLayerRenderer::QgsPointCloudLayerRenderer( QgsPointCloudLayer *layer, QgsRenderContext &context )
: QgsMapLayerRenderer( layer->id(), &context )
@@ -252,16 +254,35 @@ QVector<QMap<QString, QVariant>> QgsPointCloudLayerRenderer::identify( const Qgs
continue;
}
}
QgsPointXY deviceCoords = context.renderContext().mapToPixel().transform( QgsPointXY( x, y ) );
bool intersects = false;
// TODO: ask about this
// For some reason I need to multiply the pointSize by 2 to have correct point selection behaviour
// Inconvenience: whwn a point is not fully inside the selection area it gets selected too
QgsPointXY point1( deviceCoords.x() - 2 * mRenderer->pointSize(), deviceCoords.y() - 2 * mRenderer->pointSize() );
QgsPointXY point2( deviceCoords.x() + 2 * mRenderer->pointSize(), deviceCoords.y() + 2 * mRenderer->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 );
if ( geometry.intersects( pointRect ) )
if ( mRenderer->pointSymbol() == QgsPointCloudRenderer::PointSymbol::Square )
{
QgsPointXY deviceCoords = context.renderContext().mapToPixel().transform( QgsPointXY( x, y ) );
QgsPointXY point1( deviceCoords.x() - 2 * mRenderer->pointSize(), deviceCoords.y() - 2 * mRenderer->pointSize() );
QgsPointXY point2( deviceCoords.x() + 2 * mRenderer->pointSize(), deviceCoords.y() + 2 * mRenderer->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 );
intersects = geometry.intersects( pointRect );
}
else if ( mRenderer->pointSymbol() == QgsPointCloudRenderer::PointSymbol::Circle )
{
QgsPoint centerMapCoords( x, y );
QgsPointXY deviceCoords = context.renderContext().mapToPixel().transform( centerMapCoords );
QgsPoint point1( deviceCoords.x(), deviceCoords.y() - 2 * mRenderer->pointSize() );
QgsPoint point2( deviceCoords.x(), deviceCoords.y() + 2 * mRenderer->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 );
intersects = geometry.intersects( circleGeometry );
}
if ( intersects )
{
QMap<QString, QVariant> pointAttr = context.attributeMap( ptr, i * recordSize, blockAttributes );
pointAttr[ QStringLiteral( "X" ) ] = x;

0 comments on commit 07512be

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