Skip to content
Permalink
Browse files

fixes #18497 : Correct line size method when snapping multipolygon

  • Loading branch information
troopa81 authored and nyalldawson committed Jan 28, 2019
1 parent 9eb298f commit 4d335886fb1fb4a7a89df0e65280d1d17da86c51
Showing with 21 additions and 1 deletion.
  1. +2 −1 src/analysis/vector/qgsgeometrysnapper.cpp
  2. +19 −0 tests/src/analysis/testqgsgeometrysnapper.cpp
@@ -23,6 +23,7 @@
#include "qgsgeometryutils.h"
#include "qgsmapsettings.h"
#include "qgssurface.h"
#include "qgsmultisurface.h"
#include "qgscurve.h"

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

if ( qgsgeometry_cast< const QgsSurface * >( geom ) )
if ( qgsgeometry_cast< const QgsSurface * >( geom ) || qgsgeometry_cast< const QgsMultiSurface * >( geom ) )
{
QgsPoint front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
@@ -50,6 +50,7 @@ class TestQgsGeometrySnapper : public QObject
void internalSnapper();
void insertExtra();
void duplicateNodes();
void snapMultiPolygonToPolygon();
};

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

}

void TestQgsGeometrySnapper::snapMultiPolygonToPolygon()
{
QgsVectorLayer *rl = new QgsVectorLayer( QStringLiteral( "Polygon" ), QStringLiteral( "x" ), QStringLiteral( "memory" ) );
QgsFeature ff( 0 );
QgsGeometry refGeom = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0 0, 10 0, 10 10, 0 10, 0 0))" ) );
ff.setGeometry( refGeom );
QgsFeatureList flist;
flist << ff;
rl->dataProvider()->addFeatures( flist );

// test MultiPolygon that could be removed in the process https://issues.qgis.org/issues/18497
QgsGeometry polygonGeom = QgsGeometry::fromWkt( QStringLiteral( "MultiPolygon(((0.1 -0.1, 5 0.1, 9.9 0.1, 0.1 -0.1)))" ) );
QgsGeometrySnapper snapper( rl );
QgsGeometry result = snapper.snapGeometry( polygonGeom, 1 );
QCOMPARE( result.asWkt(), QStringLiteral( "MultiPolygon (((0 0, 5 0, 10 0, 0 0)))" ) );

}


QGSTEST_MAIN( TestQgsGeometrySnapper )
#include "testqgsgeometrysnapper.moc"

0 comments on commit 4d33588

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