Skip to content

Commit f29b55a

Browse files
committed
Fix regression with snapping on intersection (fixes #13020)
1 parent 19fdb33 commit f29b55a

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

src/core/geometry/qgsgeos.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ email : marco.hugentobler at sourcepole dot com
2020
#include "qgslinestringv2.h"
2121
#include "qgsmessagelog.h"
2222
#include "qgsmulticurvev2.h"
23+
#include "qgsmultilinestringv2.h"
2324
#include "qgsmultipointv2.h"
2425
#include "qgsmultipolygonv2.h"
2526
#include "qgslogger.h"
@@ -821,17 +822,17 @@ QgsAbstractGeometryV2* QgsGeos::fromGeos( const GEOSGeometry* geos )
821822
}
822823
case GEOS_MULTILINESTRING:
823824
{
824-
QgsMultiCurveV2* multiCurve = new QgsMultiCurveV2();
825+
QgsMultiLineStringV2* multiLineString = new QgsMultiLineStringV2();
825826
int nParts = GEOSGetNumGeometries_r( geosinit.ctxt, geos );
826827
for ( int i = 0; i < nParts; ++i )
827828
{
828829
QgsLineStringV2* line = sequenceToLinestring( GEOSGetGeometryN_r( geosinit.ctxt, geos, i ), hasZ, hasM );
829830
if ( line )
830831
{
831-
multiCurve->addGeometry( line );
832+
multiLineString->addGeometry( line );
832833
}
833834
}
834-
return multiCurve;
835+
return multiLineString;
835836
}
836837
case GEOS_MULTIPOLYGON:
837838
{

tests/src/core/testqgssnappingutils.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,52 @@ class TestQgsSnappingUtils : public QObject
170170
QVERIFY( !m2.isValid() );
171171
}
172172

173+
void testSnapOnIntersection()
174+
{
175+
// testing with a layer with two crossing linestrings
176+
// (0,1) x x (1,1)
177+
// \/
178+
// /\ .
179+
// (0,0) x x (1,0)
180+
QgsVectorLayer* vl = new QgsVectorLayer( "LineString", "x", "memory" );
181+
QgsPolyline polyline1, polyline2;
182+
polyline1 << QgsPoint( 0, 0 ) << QgsPoint( 1, 1 );
183+
polyline2 << QgsPoint( 1, 0 ) << QgsPoint( 0, 1 );
184+
QgsFeature f1;
185+
f1.setGeometry( QgsGeometry::fromPolyline( polyline1 ) );
186+
QgsFeature f2;
187+
f2.setGeometry( QgsGeometry::fromPolyline( polyline2 ) );
188+
QgsFeatureList flist;
189+
flist << f1 << f2;
190+
vl->dataProvider()->addFeatures( flist );
191+
192+
QVERIFY( vl->dataProvider()->featureCount() == 2 );
193+
194+
QgsMapSettings mapSettings;
195+
mapSettings.setOutputSize( QSize( 100, 100 ) );
196+
mapSettings.setExtent( QgsRectangle( 0, 0, 1, 1 ) );
197+
QVERIFY( mapSettings.hasValidSettings() );
198+
199+
QgsSnappingUtils u;
200+
u.setMapSettings( mapSettings );
201+
u.setSnapToMapMode( QgsSnappingUtils::SnapAdvanced );
202+
QList<QgsSnappingUtils::LayerConfig> layers;
203+
layers << QgsSnappingUtils::LayerConfig( vl, QgsPointLocator::Vertex, 0.1, QgsTolerance::MapUnits );
204+
u.setLayers( layers );
205+
206+
// no snapping on intersections by default - should find nothing
207+
QgsPointLocator::Match m = u.snapToMap( QgsPoint( 0.45, 0.5 ) );
208+
QVERIFY( !m.isValid() );
209+
210+
u.setSnapOnIntersections( true );
211+
212+
QgsPointLocator::Match m2 = u.snapToMap( QgsPoint( 0.45, 0.5 ) );
213+
QVERIFY( m2.isValid() );
214+
QCOMPARE( m2.type(), QgsPointLocator::Vertex );
215+
QCOMPARE( m2.point(), QgsPoint( 0.5, 0.5 ) );
216+
217+
delete vl;
218+
}
173219
};
174220

175221
QTEST_MAIN( TestQgsSnappingUtils )

0 commit comments

Comments
 (0)