Skip to content
Permalink
Browse files

Merge pull request #39194 from lbartoletti/vertex_tool_snapping_inter…

…polate_z_segment

Fix Z interpolation on vertex moved/added by the vertex tool.
  • Loading branch information
pblottiere committed Oct 21, 2020
2 parents 22b622b + 22ee3d0 commit 7c38853df65c9bd545f1b997a67573c4bb269e3f
Showing with 9 additions and 5 deletions.
  1. +5 −1 src/app/vertextool/qgsvertextool.cpp
  2. +2 −2 src/core/qgspointlocator.cpp
  3. +2 −2 tests/src/app/testqgsvertextool.cpp
@@ -2080,6 +2080,10 @@ void QgsVertexTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocato

QgsPoint layerPoint = matchToLayerPoint( dragLayer, mapPoint, mapPointMatch );

// needed to get Z value
if ( mapPointMatch && mapPointMatch->layer() && QgsWkbTypes::hasZ( mapPointMatch->layer()->wkbType() ) && ( mapPointMatch->hasEdge() || mapPointMatch->hasMiddleSegment() ) )
layerPoint = mapPointMatch->interpolatedPoint();

QgsVertexId vid;
if ( !geom.vertexIdFromVertexNr( dragVertexId, vid ) )
{
@@ -2130,7 +2134,7 @@ void QgsVertexTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocato

applyEditsToLayers( edits );

if ( QgsProject::instance()->topologicalEditing() && mapPointMatch->hasEdge() && mapPointMatch->layer() )
if ( QgsProject::instance()->topologicalEditing() && ( mapPointMatch->hasEdge() || mapPointMatch->hasMiddleSegment() ) && mapPointMatch->layer() )
{
// topo editing: add vertex to existing segments when moving/adding a vertex to such segment.
// this requires that the snapping match is to a segment and the segment layer's CRS
@@ -228,7 +228,7 @@ class QgsPointLocator_VisitorNearestMiddleOfSegment: public IVisitor
edgePoints[1] = geom->vertexAt( afterVertex );
pt = QgsPointXY( ( edgePoints[0].x() + edgePoints[1].x() ) / 2.0, ( edgePoints[0].y() + edgePoints[1].y() ) / 2.0 );

QgsPointLocator::Match m( QgsPointLocator::MiddleOfSegment, mLocator->mLayer, id, std::sqrt( mSrcPoint.sqrDist( pt ) ), pt, -1 );
QgsPointLocator::Match m( QgsPointLocator::MiddleOfSegment, mLocator->mLayer, id, std::sqrt( mSrcPoint.sqrDist( pt ) ), pt, afterVertex - 1 );
// in range queries the filter may reject some matches
if ( mFilter && !mFilter->acceptMatch( m ) )
return;
@@ -661,7 +661,7 @@ class QgsPointLocator_VisitorMiddlesInRect : public IVisitor
QgsPointXY pt( ( ( *itPrevious ).x() + ( *it ).x() ) / 2.0, ( ( *itPrevious ).y() + ( *it ).y() ) / 2.0 );
if ( mSrcRect.contains( pt ) )
{
QgsPointLocator::Match m( QgsPointLocator::MiddleOfSegment, mLocator->mLayer, id, 0, pt, -1 );
QgsPointLocator::Match m( QgsPointLocator::MiddleOfSegment, mLocator->mLayer, id, 0, pt, geom->vertexNrFromVertexId( it.vertexId() ) );

// in range queries the filter may reject some matches
if ( mFilter && !mFilter->acceptMatch( m ) )
@@ -385,8 +385,8 @@ void TestQgsVertexTool::testTopologicalEditingMoveVertexOnSegmentZ()
mouseClick( 6, 6, Qt::LeftButton, Qt::KeyboardModifiers(), true );
mouseClick( 6, 7, Qt::LeftButton, Qt::KeyboardModifiers(), true );

QCOMPARE( mLayerLineZ->getFeature( mFidLineZF1 ).geometry().asWkt(), QString( "LineStringZ (5 5 1, 6 7 1, 7 5 1)" ) );
QCOMPARE( mLayerLineZ->getFeature( mFidLineZF2 ).geometry().asWkt(), QString( "LineStringZ (5 7 5, 6 7 333, 7 7 10)" ) );
QCOMPARE( mLayerLineZ->getFeature( mFidLineZF1 ).geometry().asWkt(), QString( "LineStringZ (5 5 1, 6 7 7.5, 7 5 1)" ) );
QCOMPARE( mLayerLineZ->getFeature( mFidLineZF2 ).geometry().asWkt(), QString( "LineStringZ (5 7 5, 6 7 7.5, 7 7 10)" ) );

QgsProject::instance()->setTopologicalEditing( topologicalEditing );
mLayerLineZ->undoStack()->undo();

0 comments on commit 7c38853

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