Skip to content
Permalink
Browse files
Test addTopologicalPoints results
  • Loading branch information
gacarrillor authored and nyalldawson committed Jul 22, 2021
1 parent ec13b33 commit 0d504ad6d4bc65cf17407c6a59fffa01c12ea509
Showing with 24 additions and 7 deletions.
  1. +24 −7 tests/src/core/testqgsvectorlayer.cpp
@@ -350,7 +350,7 @@ void TestQgsVectorLayer::testAddTopologicalPoints()
QVERIFY( layerLine->isValid() );

QgsPolylineXY line1;
line1 << QgsPointXY( 2, 1 ) << QgsPointXY( 1, 1 ) << QgsPointXY( 1, 3 );
line1 << QgsPointXY( 2, 1 ) << QgsPointXY( 1, 1 ) << QgsPointXY( 1, 5 );
QgsFeature lineF1;
lineF1.setGeometry( QgsGeometry::fromPolylineXY( line1 ) );

@@ -362,22 +362,39 @@ void TestQgsVectorLayer::testAddTopologicalPoints()
QCOMPARE( layerLine->undoStack()->index(), 1 );

// outside of the linestring - nothing should happen
layerLine->addTopologicalPoints( QgsPoint( 2, 2 ) );
int result = layerLine->addTopologicalPoints( QgsPoint( 2, 2 ) );
QCOMPARE( result, 2 );

QCOMPARE( layerLine->undoStack()->index(), 1 );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ).asWkt() );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 5)" ).asWkt() );

// add point at an existing vertex
layerLine->addTopologicalPoints( QgsPoint( 1, 1 ) );
result = layerLine->addTopologicalPoints( QgsPoint( 1, 1 ) );
QCOMPARE( result, 2 );

QCOMPARE( layerLine->undoStack()->index(), 1 );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ).asWkt() );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 5)" ).asWkt() );

// add point on segment of linestring
layerLine->addTopologicalPoints( QgsPoint( 1, 2 ) );
result = layerLine->addTopologicalPoints( QgsPoint( 1, 2 ) );
QCOMPARE( result, 0 );

QCOMPARE( layerLine->undoStack()->index(), 2 );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 2, 1 3)" ).asWkt() );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 2, 1 5)" ).asWkt() );

// add points from disjoint geometry - nothing should happen
result = layerLine->addTopologicalPoints( QgsGeometry::fromWkt( "LINESTRING(2 0, 2 1, 2 2)" ) );
QCOMPARE( result, 2 );

QCOMPARE( layerLine->undoStack()->index(), 2 );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 2, 1 5)" ).asWkt() );

// add 2 out of 3 points from intersecting geometry
result = layerLine->addTopologicalPoints( QgsGeometry::fromWkt( "LINESTRING(2 0, 2 1, 2 3, 1 3, 0 3, 0 4, 1 4)" ) );
QCOMPARE( result, 0 );

QCOMPARE( layerLine->undoStack()->index(), 2 );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 2, 1 3, 1 4, 1 5)" ).asWkt() );

delete layerLine;
}

0 comments on commit 0d504ad

Please sign in to comment.