Skip to content
Permalink
Browse files

Fix regression with snapping on intersection (fixes #13020)

  • Loading branch information
wonder-sk committed Jun 23, 2015
1 parent 19fdb33 commit f29b55a08c346e583bf69007c4234d5116a11528
Showing with 50 additions and 3 deletions.
  1. +4 −3 src/core/geometry/qgsgeos.cpp
  2. +46 −0 tests/src/core/testqgssnappingutils.cpp
@@ -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 )

0 comments on commit f29b55a

Please sign in to comment.
You can’t perform that action at this time.