Skip to content

Commit abda6c4

Browse files
troopa81nyalldawson
authored andcommittedJan 24, 2019
fixes #18497 : Correct line size method when snapping multipolygon
1 parent 394e5d8 commit abda6c4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
 

‎src/analysis/vector/qgsgeometrysnapper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgsgeometryutils.h"
2424
#include "qgsmapsettings.h"
2525
#include "qgssurface.h"
26+
#include "qgsmultisurface.h"
2627
#include "qgscurve.h"
2728

2829
///@cond PRIVATE
@@ -718,7 +719,7 @@ int QgsGeometrySnapper::polyLineSize( const QgsAbstractGeometry *geom, int iPart
718719
{
719720
int nVerts = geom->vertexCount( iPart, iRing );
720721

721-
if ( qgsgeometry_cast< const QgsSurface * >( geom ) )
722+
if ( qgsgeometry_cast< const QgsSurface * >( geom ) || qgsgeometry_cast< const QgsMultiSurface * >( geom ) )
722723
{
723724
QgsPoint front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
724725
QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );

‎tests/src/analysis/testqgsgeometrysnapper.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class TestQgsGeometrySnapper : public QObject
5050
void internalSnapper();
5151
void insertExtra();
5252
void duplicateNodes();
53+
void snapMultiPolygonToPolygon();
5354
};
5455

5556
void TestQgsGeometrySnapper::initTestCase()
@@ -612,6 +613,24 @@ void TestQgsGeometrySnapper::duplicateNodes()
612613

613614
}
614615

616+
void TestQgsGeometrySnapper::snapMultiPolygonToPolygon()
617+
{
618+
QgsVectorLayer *rl = new QgsVectorLayer( QStringLiteral( "Polygon" ), QStringLiteral( "x" ), QStringLiteral( "memory" ) );
619+
QgsFeature ff( 0 );
620+
QgsGeometry refGeom = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0 0, 10 0, 10 10, 0 10, 0 0))" ) );
621+
ff.setGeometry( refGeom );
622+
QgsFeatureList flist;
623+
flist << ff;
624+
rl->dataProvider()->addFeatures( flist );
625+
626+
// test MultiPolygon that could be removed in the process https://issues.qgis.org/issues/18497
627+
QgsGeometry polygonGeom = QgsGeometry::fromWkt( QStringLiteral( "MultiPolygon(((0.1 -0.1, 5 0.1, 9.9 0.1, 0.1 -0.1)))" ) );
628+
QgsGeometrySnapper snapper( rl );
629+
QgsGeometry result = snapper.snapGeometry( polygonGeom, 1 );
630+
QCOMPARE( result.asWkt(), QStringLiteral( "MultiPolygon (((0 0, 5 0, 10 0, 0 0)))" ) );
631+
632+
}
633+
615634

616635
QGSTEST_MAIN( TestQgsGeometrySnapper )
617636
#include "testqgsgeometrysnapper.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.