diff --git a/python/PyQt6/core/auto_generated/vector/qgsvectorlayereditutils.sip.in b/python/PyQt6/core/auto_generated/vector/qgsvectorlayereditutils.sip.in index 2a7e6a972eca..63643833dfe2 100644 --- a/python/PyQt6/core/auto_generated/vector/qgsvectorlayereditutils.sip.in +++ b/python/PyQt6/core/auto_generated/vector/qgsvectorlayereditutils.sip.in @@ -332,6 +332,7 @@ Merge features into a single one. .. versionadded:: 3.30 %End + }; /************************************************************************ diff --git a/python/core/auto_generated/vector/qgsvectorlayereditutils.sip.in b/python/core/auto_generated/vector/qgsvectorlayereditutils.sip.in index 2a7e6a972eca..63643833dfe2 100644 --- a/python/core/auto_generated/vector/qgsvectorlayereditutils.sip.in +++ b/python/core/auto_generated/vector/qgsvectorlayereditutils.sip.in @@ -332,6 +332,7 @@ Merge features into a single one. .. versionadded:: 3.30 %End + }; /************************************************************************ diff --git a/src/app/qgsmaptooladdfeature.cpp b/src/app/qgsmaptooladdfeature.cpp index cc87dea9f72a..daf1871f30b9 100644 --- a/src/app/qgsmaptooladdfeature.cpp +++ b/src/app/qgsmaptooladdfeature.cpp @@ -28,6 +28,7 @@ #include "qgisapp.h" #include "qgsexpressioncontextutils.h" #include "qgsrubberband.h" +#include "qgsvectorlayereditutils.h" #include @@ -143,9 +144,11 @@ void QgsMapToolAddFeature::featureDigitized( const QgsFeature &feature ) } if ( topologicalEditing ) { - QgsFeatureRequest request = QgsFeatureRequest().setFilterRect( feature.geometry().boundingBox() ).setNoAttributes().setFlags( Qgis::FeatureRequestFlag::NoGeometry ).setLimit( 1 ); - request.setDestinationCrs( vlayer->crs(), vlayer->transformContext() ); + QgsFeatureRequest request = QgsFeatureRequest().setNoAttributes().setFlags( Qgis::FeatureRequestFlag::NoGeometry ).setLimit( 1 ); + QgsRectangle bbox = feature.geometry().boundingBox(); + QgsRectangle searchRect; QgsFeature f; + QgsCoordinateTransform transform; const QList layers = canvas()->layers( true ); @@ -159,6 +162,19 @@ void QgsMapToolAddFeature::featureDigitized( const QgsFeature &feature ) if ( !( vectorLayer->geometryType() == Qgis::GeometryType::Polygon || vectorLayer->geometryType() == Qgis::GeometryType::Line ) ) continue; + if ( vectorLayer->crs() == vlayer->crs() ) + { + searchRect = QgsRectangle( bbox ); + } + else + { + transform = QgsCoordinateTransform( vlayer->crs(), vectorLayer->crs(), vectorLayer->transformContext() ); + searchRect = transform.transformBoundingBox( bbox ); + } + + searchRect.grow( QgsVectorLayerEditUtils::getTopologicalSearchRadius( vectorLayer ) ); + request.setFilterRect( searchRect ); + if ( !vectorLayer->getFeatures( request ).nextFeature( f ) ) continue; diff --git a/src/app/vertextool/qgsvertextool.cpp b/src/app/vertextool/qgsvertextool.cpp index ba7f26954425..69ffd7f41a19 100644 --- a/src/app/vertextool/qgsvertextool.cpp +++ b/src/app/vertextool/qgsvertextool.cpp @@ -43,6 +43,7 @@ #include "qgsexpressioncontextutils.h" #include "qgsmessagebar.h" #include "qgssettingsentryimpl.h" +#include "qgsvectorlayereditutils.h" #include @@ -2204,7 +2205,9 @@ void QgsVertexTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocato { // topo editing: add vertex to existing segments when moving/adding a vertex to such segment. - QgsFeatureRequest request = QgsFeatureRequest().setFilterRect( layerPoint.boundingBox() ).setDestinationCrs( dragLayer->crs(), mCanvas->mapSettings().transformContext() ).setNoAttributes().setFlags( Qgis::FeatureRequestFlag::NoGeometry ).setLimit( 1 ); + QgsFeatureRequest request = QgsFeatureRequest().setNoAttributes().setFlags( Qgis::FeatureRequestFlag::NoGeometry ).setLimit( 1 ); + QgsRectangle bbox = layerPoint.boundingBox(); + QgsRectangle searchRect; QgsFeature f; const QList targetLayers = canvas()->layers( true ); @@ -2225,6 +2228,10 @@ void QgsVertexTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocato if ( vectorLayer->crs() != itLayerEdits.key()->crs() ) continue; + searchRect = QgsRectangle( bbox ); + searchRect.grow( QgsVectorLayerEditUtils::getTopologicalSearchRadius( vectorLayer ) ); + request.setFilterRect( searchRect ); + if ( !vectorLayer->getFeatures( request ).nextFeature( f ) ) continue; diff --git a/src/core/vector/qgsvectorlayereditutils.cpp b/src/core/vector/qgsvectorlayereditutils.cpp index 17df3e729fb3..c1a74f717b32 100644 --- a/src/core/vector/qgsvectorlayereditutils.cpp +++ b/src/core/vector/qgsvectorlayereditutils.cpp @@ -211,6 +211,29 @@ Qgis::GeometryOperationResult staticAddRing( QgsVectorLayer *layer, std::unique_ return success ? Qgis::GeometryOperationResult::Success : addRingReturnCode; } +// this method might be inlined later on +///@cond PRIVATE +double QgsVectorLayerEditUtils::getTopologicalSearchRadius( const QgsVectorLayer *layer ) +{ + double threshold = layer->geometryOptions()->geometryPrecision(); + + if ( qgsDoubleNear( threshold, 0.0 ) ) + { + threshold = 1e-8; + + if ( layer->crs().mapUnits() == Qgis::DistanceUnit::Meters ) + { + threshold = 0.001; + } + else if ( layer->crs().mapUnits() == Qgis::DistanceUnit::Feet ) + { + threshold = 0.0001; + } + } + return threshold; +} +///@endcond + Qgis::GeometryOperationResult QgsVectorLayerEditUtils::addRing( const QVector &ring, const QgsFeatureIds &targetFeatureIds, QgsFeatureId *modifiedFeatureId ) { QgsPointSequence l; @@ -801,21 +824,7 @@ int QgsVectorLayerEditUtils::addTopologicalPoints( const QgsPoint &p ) double segmentSearchEpsilon = mLayer->crs().isGeographic() ? 1e-12 : 1e-8; //work with a tolerance because coordinate projection may introduce some rounding - double threshold = mLayer->geometryOptions()->geometryPrecision(); - - if ( qgsDoubleNear( threshold, 0.0 ) ) - { - threshold = 1e-8; - - if ( mLayer->crs().mapUnits() == Qgis::DistanceUnit::Meters ) - { - threshold = 0.001; - } - else if ( mLayer->crs().mapUnits() == Qgis::DistanceUnit::Feet ) - { - threshold = 0.0001; - } - } + double threshold = getTopologicalSearchRadius( mLayer ); QgsRectangle searchRect( p, p, false ); searchRect.grow( threshold ); diff --git a/src/core/vector/qgsvectorlayereditutils.h b/src/core/vector/qgsvectorlayereditutils.h index c2443c4d241e..7571042fae32 100644 --- a/src/core/vector/qgsvectorlayereditutils.h +++ b/src/core/vector/qgsvectorlayereditutils.h @@ -282,6 +282,10 @@ class CORE_EXPORT QgsVectorLayerEditUtils */ bool mergeFeatures( const QgsFeatureId &targetFeatureId, const QgsFeatureIds &mergeFeatureIds, const QgsAttributes &mergeAttributes, const QgsGeometry &unionGeometry, QString &errorMessage SIP_OUT ); + ///@cond PRIVATE + static double getTopologicalSearchRadius( const QgsVectorLayer *layer ) SIP_SKIP; + ///@endcond + private: /**