Skip to content
Permalink
Browse files

Respect identify tool tolerance when identifying small point cloud ma…

…rkers
  • Loading branch information
nyalldawson authored and wonder-sk committed Jan 4, 2021
1 parent 30084f6 commit cc737571f6e9871d992de31aeff87f6a002e990e
@@ -195,7 +195,7 @@ void QgsPointCloudRenderer::setPointSymbol( PointSymbol symbol )
mPointSymbol = symbol;
}

QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer, const QgsRenderContext &renderContext, const QgsGeometry &geometry )
QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer, const QgsRenderContext &renderContext, const QgsGeometry &geometry, double toleranceForPointIdentification )
{
QVector<QVariantMap> selectedPoints;

@@ -234,13 +234,15 @@ QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer,
{
double x = geometry.asPoint().x();
double y = geometry.asPoint().y();
const double toleranceInPixels = toleranceForPointIdentification / renderContext.mapToPixel().mapUnitsPerPixel();
const double pointSizePixels = renderContext.convertToPainterUnits( mPointSize, mPointSizeUnit, mPointSizeMapUnitScale );
switch ( pointSymbol() )
{
case QgsPointCloudRenderer::PointSymbol::Square:
{
QgsPointXY deviceCoords = 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 point1( deviceCoords.x() - std::max( toleranceInPixels, pointSizePixels / 2.0 ), deviceCoords.y() - std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
QgsPointXY point2( deviceCoords.x() + std::max( toleranceInPixels, pointSizePixels / 2.0 ), deviceCoords.y() + std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
QgsPointXY point1MapCoords = renderContext.mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = renderContext.mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsRectangle pointRect( point1MapCoords, point2MapCoords );
@@ -251,8 +253,8 @@ QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer,
{
QgsPoint centerMapCoords( x, y );
QgsPointXY deviceCoords = renderContext.mapToPixel().transform( centerMapCoords );
QgsPoint point1( deviceCoords.x(), deviceCoords.y() - 2 * pointSize() );
QgsPoint point2( deviceCoords.x(), deviceCoords.y() + 2 * pointSize() );
QgsPoint point1( deviceCoords.x(), deviceCoords.y() - std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
QgsPoint point2( deviceCoords.x(), deviceCoords.y() + std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
QgsPointXY point1MapCoords = renderContext.mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = renderContext.mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsCircle circle = QgsCircle::from2Points( QgsPoint( point1MapCoords ), QgsPoint( point2MapCoords ) );
@@ -285,9 +285,12 @@ class CORE_EXPORT QgsPointCloudRenderer
* Returns the list of visible points of the point cloud layer \a layer and an extent defined by
* a geometry in the 2D plane \a geometry.
*
* The \a toleranceForPointIdentification argument can be used to specify a minimum tolerance allowable when
* identify from a point \a geometry value. This must be specified in the map units associated with the render \a context.
*
* \warning The \a geometry value must be specified in the render context's destination CRS, not the layer's native CRS!
*/
QVector<QVariantMap> identify( QgsPointCloudLayer *layer, const QgsRenderContext &context, const QgsGeometry &geometry ) SIP_SKIP;
QVector<QVariantMap> identify( QgsPointCloudLayer *layer, const QgsRenderContext &context, const QgsGeometry &geometry, double toleranceForPointIdentification = 0 ) SIP_SKIP;

/**
* Checks whether the point holding \a pointAttributes attributes will be rendered
@@ -513,7 +513,9 @@ bool QgsMapToolIdentify::identifyPointCloudLayer( QList<QgsMapToolIdentify::Iden
QgsRenderContext context = QgsRenderContext::fromMapSettings( mCanvas->mapSettings() );
context.setCoordinateTransform( QgsCoordinateTransform( layer->crs(), mCanvas->mapSettings().destinationCrs(), mCanvas->mapSettings().transformContext() ) );

const QVector<QVariantMap> points = renderer->identify( layer, context, geometry );
const double searchRadiusMapUnits = mOverrideCanvasSearchRadius < 0 ? searchRadiusMU( mCanvas ) : mOverrideCanvasSearchRadius;

const QVector<QVariantMap> points = renderer->identify( layer, context, geometry, searchRadiusMapUnits );
int id = 0;
const QgsPointCloudLayerElevationProperties *elevationProps = qobject_cast< const QgsPointCloudLayerElevationProperties *>( layer->elevationProperties() );
for ( const QVariantMap &pt : points )

0 comments on commit cc73757

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