Skip to content

Commit

Permalink
tweak match from nearestEdge to return an Area type
Browse files Browse the repository at this point in the history
also make that VisitorArea return the given point as the match point
  • Loading branch information
3nids committed Feb 19, 2018
1 parent 1d0043e commit 3f9963e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/core/qgspointlocator.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}


Expand Down
4 changes: 3 additions & 1 deletion tests/src/core/testqgspointlocator.cpp
Expand Up @@ -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()
Expand Down

0 comments on commit 3f9963e

Please sign in to comment.