Skip to content

Commit

Permalink
Merge pull request #33642 from lbartoletti/fix_snap_3d_on_2d_vertex
Browse files Browse the repository at this point in the history
Fix ZM snapping for line/polygon on 2D vertex
  • Loading branch information
m-kuhn committed Jan 14, 2020
2 parents 18549fa + cba532f commit a47bbf4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -410,6 +410,10 @@ int QgsMapToolCapture::fetchLayerPoint( const QgsPointLocator::Match &match, Qgs
else
{
layerPoint = geom.constGet()->vertexAt( vId );
if ( QgsWkbTypes::hasZ( vlayer->wkbType() ) && !layerPoint.is3D() )
layerPoint.addZValue( defaultZValue() );
if ( QgsWkbTypes::hasM( vlayer->wkbType() ) && !layerPoint.isMeasure() )
layerPoint.addMValue( 0.0 );
}

// ZM support depends on the target layer
Expand Down
35 changes: 34 additions & 1 deletion tests/src/app/testqgsmaptooladdfeatureline.cpp
Expand Up @@ -79,6 +79,7 @@ class TestQgsMapToolAddFeatureLine : public QObject
QgsVectorLayer *mLayerLineZ = nullptr;
QgsVectorLayer *mLayerPointZM = nullptr;
QgsVectorLayer *mLayerTopoZ = nullptr;
QgsVectorLayer *mLayerLine2D = nullptr;
QgsFeatureId mFidLineF1 = 0;
};

Expand Down Expand Up @@ -169,7 +170,18 @@ void TestQgsMapToolAddFeatureLine::initTestCase()
mLayerTopoZ->addFeature( topoFeat );
QCOMPARE( mLayerTopoZ->featureCount(), ( long ) 1 );

mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerLine << mLayerLineZ << mLayerPointZM << mLayerTopoZ );
// make 2D layer for snapping with a 3D layer
mLayerLine2D = new QgsVectorLayer( QStringLiteral( "LineString?crs=EPSG:27700" ), QStringLiteral( "layer line" ), QStringLiteral( "memory" ) );
QVERIFY( mLayerLine2D->isValid() );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerLine2D );

mLayerLine2D->startEditing();
QgsFeature lineString2DF;
lineString2DF.setGeometry( QgsGeometry::fromWkt( "LineString ((8 8, 9 9))" ) );

mLayerLine2D->addFeature( lineString2DF );
QCOMPARE( mLayerLine2D->featureCount(), ( long )1 );
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerLine << mLayerLineZ << mLayerPointZM << mLayerTopoZ << mLayerLine2D );

mCanvas->setSnappingUtils( new QgsMapCanvasSnappingUtils( mCanvas, this ) );

Expand Down Expand Up @@ -406,6 +418,27 @@ void TestQgsMapToolAddFeatureLine::testZMSnapping()

mLayerLine->undoStack()->undo();

mCanvas->setCurrentLayer( mLayerLineZ );
oldFids = utils.existingFeatureIds();
// test with default Z value = 222
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 );
// snap a on a layer without ZM support
utils.mouseClick( 9, 9, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseClick( 8, 7, Qt::LeftButton );
utils.mouseClick( 5, 0, Qt::RightButton );

newFid = utils.newFeatureId( oldFids );

QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry().get()->is3D(), true );

QString wkt = "LineStringZ (9 9 222, 8 7 222)";
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry().get()->isMeasure(), false );

mLayerLine->undoStack()->undo();

cfg.setEnabled( false );

cfg.setEnabled( false );
mCanvas->snappingUtils()->setConfig( cfg );
}
Expand Down

0 comments on commit a47bbf4

Please sign in to comment.