mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Fix regression with snapping on intersection (fixes #13020)
This commit is contained in:
parent
19fdb3389b
commit
f29b55a08c
@ -20,6 +20,7 @@ email : marco.hugentobler at sourcepole dot com
|
||||
#include "qgslinestringv2.h"
|
||||
#include "qgsmessagelog.h"
|
||||
#include "qgsmulticurvev2.h"
|
||||
#include "qgsmultilinestringv2.h"
|
||||
#include "qgsmultipointv2.h"
|
||||
#include "qgsmultipolygonv2.h"
|
||||
#include "qgslogger.h"
|
||||
@ -821,17 +822,17 @@ QgsAbstractGeometryV2* QgsGeos::fromGeos( const GEOSGeometry* geos )
|
||||
}
|
||||
case GEOS_MULTILINESTRING:
|
||||
{
|
||||
QgsMultiCurveV2* multiCurve = new QgsMultiCurveV2();
|
||||
QgsMultiLineStringV2* multiLineString = new QgsMultiLineStringV2();
|
||||
int nParts = GEOSGetNumGeometries_r( geosinit.ctxt, geos );
|
||||
for ( int i = 0; i < nParts; ++i )
|
||||
{
|
||||
QgsLineStringV2* line = sequenceToLinestring( GEOSGetGeometryN_r( geosinit.ctxt, geos, i ), hasZ, hasM );
|
||||
if ( line )
|
||||
{
|
||||
multiCurve->addGeometry( line );
|
||||
multiLineString->addGeometry( line );
|
||||
}
|
||||
}
|
||||
return multiCurve;
|
||||
return multiLineString;
|
||||
}
|
||||
case GEOS_MULTIPOLYGON:
|
||||
{
|
||||
|
@ -170,6 +170,52 @@ class TestQgsSnappingUtils : public QObject
|
||||
QVERIFY( !m2.isValid() );
|
||||
}
|
||||
|
||||
void testSnapOnIntersection()
|
||||
{
|
||||
// testing with a layer with two crossing linestrings
|
||||
// (0,1) x x (1,1)
|
||||
// \/
|
||||
// /\ .
|
||||
// (0,0) x x (1,0)
|
||||
QgsVectorLayer* vl = new QgsVectorLayer( "LineString", "x", "memory" );
|
||||
QgsPolyline polyline1, polyline2;
|
||||
polyline1 << QgsPoint( 0, 0 ) << QgsPoint( 1, 1 );
|
||||
polyline2 << QgsPoint( 1, 0 ) << QgsPoint( 0, 1 );
|
||||
QgsFeature f1;
|
||||
f1.setGeometry( QgsGeometry::fromPolyline( polyline1 ) );
|
||||
QgsFeature f2;
|
||||
f2.setGeometry( QgsGeometry::fromPolyline( polyline2 ) );
|
||||
QgsFeatureList flist;
|
||||
flist << f1 << f2;
|
||||
vl->dataProvider()->addFeatures( flist );
|
||||
|
||||
QVERIFY( vl->dataProvider()->featureCount() == 2 );
|
||||
|
||||
QgsMapSettings mapSettings;
|
||||
mapSettings.setOutputSize( QSize( 100, 100 ) );
|
||||
mapSettings.setExtent( QgsRectangle( 0, 0, 1, 1 ) );
|
||||
QVERIFY( mapSettings.hasValidSettings() );
|
||||
|
||||
QgsSnappingUtils u;
|
||||
u.setMapSettings( mapSettings );
|
||||
u.setSnapToMapMode( QgsSnappingUtils::SnapAdvanced );
|
||||
QList<QgsSnappingUtils::LayerConfig> layers;
|
||||
layers << QgsSnappingUtils::LayerConfig( vl, QgsPointLocator::Vertex, 0.1, QgsTolerance::MapUnits );
|
||||
u.setLayers( layers );
|
||||
|
||||
// no snapping on intersections by default - should find nothing
|
||||
QgsPointLocator::Match m = u.snapToMap( QgsPoint( 0.45, 0.5 ) );
|
||||
QVERIFY( !m.isValid() );
|
||||
|
||||
u.setSnapOnIntersections( true );
|
||||
|
||||
QgsPointLocator::Match m2 = u.snapToMap( QgsPoint( 0.45, 0.5 ) );
|
||||
QVERIFY( m2.isValid() );
|
||||
QCOMPARE( m2.type(), QgsPointLocator::Vertex );
|
||||
QCOMPARE( m2.point(), QgsPoint( 0.5, 0.5 ) );
|
||||
|
||||
delete vl;
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN( TestQgsSnappingUtils )
|
||||
|
Loading…
x
Reference in New Issue
Block a user