Skip to content

Commit

Permalink
Fix regression with snapping on intersection (fixes #13020)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jun 23, 2015
1 parent 19fdb33 commit f29b55a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/core/geometry/qgsgeos.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
{
Expand Down
46 changes: 46 additions & 0 deletions tests/src/core/testqgssnappingutils.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit f29b55a

Please sign in to comment.