mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-25 00:03:06 -04:00
fixes #18497 : Correct line size method when snapping multipolygon
This commit is contained in:
parent
394e5d8d76
commit
abda6c42ff
@ -23,6 +23,7 @@
|
|||||||
#include "qgsgeometryutils.h"
|
#include "qgsgeometryutils.h"
|
||||||
#include "qgsmapsettings.h"
|
#include "qgsmapsettings.h"
|
||||||
#include "qgssurface.h"
|
#include "qgssurface.h"
|
||||||
|
#include "qgsmultisurface.h"
|
||||||
#include "qgscurve.h"
|
#include "qgscurve.h"
|
||||||
|
|
||||||
///@cond PRIVATE
|
///@cond PRIVATE
|
||||||
@ -718,7 +719,7 @@ int QgsGeometrySnapper::polyLineSize( const QgsAbstractGeometry *geom, int iPart
|
|||||||
{
|
{
|
||||||
int nVerts = geom->vertexCount( iPart, iRing );
|
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 front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
|
||||||
QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
|
QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
|
||||||
|
@ -50,6 +50,7 @@ class TestQgsGeometrySnapper : public QObject
|
|||||||
void internalSnapper();
|
void internalSnapper();
|
||||||
void insertExtra();
|
void insertExtra();
|
||||||
void duplicateNodes();
|
void duplicateNodes();
|
||||||
|
void snapMultiPolygonToPolygon();
|
||||||
};
|
};
|
||||||
|
|
||||||
void TestQgsGeometrySnapper::initTestCase()
|
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 )
|
QGSTEST_MAIN( TestQgsGeometrySnapper )
|
||||||
#include "testqgsgeometrysnapper.moc"
|
#include "testqgsgeometrysnapper.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user