Skip to content

Commit

Permalink
Merge pull request #39194 from lbartoletti/vertex_tool_snapping_inter…
Browse files Browse the repository at this point in the history
…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 7c38853
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -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 ) )
{
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgspointlocator.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) )
Expand Down
4 changes: 2 additions & 2 deletions tests/src/app/testqgsvertextool.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit 7c38853

Please sign in to comment.