Skip to content
Permalink
Browse files

Merge pull request #33642 from lbartoletti/fix_snap_3d_on_2d_vertex

Fix ZM snapping for line/polygon on 2D vertex
  • Loading branch information
m-kuhn committed Jan 14, 2020
2 parents 18549fa + cba532f commit a47bbf4148ccdc4c64e6785e2749c41f6a60fc05
Showing with 38 additions and 1 deletion.
  1. +4 −0 src/gui/qgsmaptoolcapture.cpp
  2. +34 −1 tests/src/app/testqgsmaptooladdfeatureline.cpp
@@ -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
@@ -79,6 +79,7 @@ class TestQgsMapToolAddFeatureLine : public QObject
QgsVectorLayer *mLayerLineZ = nullptr;
QgsVectorLayer *mLayerPointZM = nullptr;
QgsVectorLayer *mLayerTopoZ = nullptr;
QgsVectorLayer *mLayerLine2D = nullptr;
QgsFeatureId mFidLineF1 = 0;
};

@@ -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 ) );

@@ -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 );
}

0 comments on commit a47bbf4

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