fixes #18497 : Correct line size method when snapping multipolygon

This commit is contained in:
Julien Cabieces 2019-01-24 10:21:40 +01:00 committed by Nyall Dawson
parent 394e5d8d76
commit abda6c42ff
2 changed files with 21 additions and 1 deletions

View File

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

View File

@ -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"