Skip to content

Commit

Permalink
fixes #18497 : Correct line size method when snapping multipolygon
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 authored and nyalldawson committed Jan 24, 2019
1 parent 394e5d8 commit abda6c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/analysis/vector/qgsgeometrysnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgsgeometryutils.h"
#include "qgsmapsettings.h"
#include "qgssurface.h"
#include "qgsmultisurface.h"
#include "qgscurve.h"

///@cond PRIVATE
Expand Down Expand Up @@ -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 ) );
Expand Down
19 changes: 19 additions & 0 deletions tests/src/analysis/testqgsgeometrysnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class TestQgsGeometrySnapper : public QObject
void internalSnapper();
void insertExtra();
void duplicateNodes();
void snapMultiPolygonToPolygon();
};

void TestQgsGeometrySnapper::initTestCase()
Expand Down Expand Up @@ -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 abda6c4

Please sign in to comment.