Skip to content
Permalink
Browse files

tweak match from nearestEdge to return an Area type

also make that VisitorArea return the given point as the match point
  • Loading branch information
3nids committed Feb 19, 2018
1 parent 1d0043e commit 3f9963e2482d20fa2c5191f4a203fb1c4cbf84bd
Showing with 9 additions and 3 deletions.
  1. +6 −2 src/core/qgspointlocator.cpp
  2. +3 −1 tests/src/core/testqgspointlocator.cpp
@@ -204,7 +204,7 @@ class QgsPointLocator_VisitorArea : public IVisitor
QgsFeatureId id = d.getIdentifier();
QgsGeometry *g = mLocator->mGeoms.value( id );
if ( g->intersects( mGeomPt ) )
mList << QgsPointLocator::Match( QgsPointLocator::Area, mLocator->mLayer, id, 0, QgsPointXY() );
mList << QgsPointLocator::Match( QgsPointLocator::Area, mLocator->mLayer, id, 0, mGeomPt.asPoint() );
}
private:
QgsPointLocator *mLocator = nullptr;
@@ -908,7 +908,11 @@ QgsPointLocator::Match QgsPointLocator::nearestArea( const QgsPointXY &point, do
return Match();

// use edges for adding tolerance
return nearestEdge( point, tolerance, filter );
Match m = nearestEdge( point, tolerance, filter );
if ( m.isValid() )
return Match( Area, m.layer(), m.featureId(), m.distance(), m.point() );
else
return Match();
}


@@ -144,14 +144,16 @@ class TestQgsPointLocator : public QObject
QCOMPARE( m2.layer(), mVL );
QCOMPARE( m2.featureId(), ( QgsFeatureId )1 );
QCOMPARE( m2.point(), QgsPointXY( 0.9, 0.9 ) );
QCOMPARE( m2.distance(), 0 );

QgsPointXY pt3( 1.1, 1.1 );
QgsPointLocator::Match m3 = loc.nearestArea( pt3, 999 );
QVERIFY( m3.isValid() );
QVERIFY( m3.hasArea() );
QCOMPARE( m3.layer(), mVL );
QCOMPARE( m3.featureId(), ( QgsFeatureId )1 );
QCOMPARE( m3.point(), QgsPointXY( 1.0, 1 - 0 ) );
QCOMPARE( m3.point(), QgsPointXY( 1.0, 1.0 ) );
QCOMPARE( m3.distance(), .1 * std::sqrt( 2 ) );
}

void testPointInPolygon()

0 comments on commit 3f9963e

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