Skip to content

Commit 3f9963e

Browse files
committedFeb 19, 2018
tweak match from nearestEdge to return an Area type
also make that VisitorArea return the given point as the match point
1 parent 1d0043e commit 3f9963e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
 

‎src/core/qgspointlocator.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class QgsPointLocator_VisitorArea : public IVisitor
204204
QgsFeatureId id = d.getIdentifier();
205205
QgsGeometry *g = mLocator->mGeoms.value( id );
206206
if ( g->intersects( mGeomPt ) )
207-
mList << QgsPointLocator::Match( QgsPointLocator::Area, mLocator->mLayer, id, 0, QgsPointXY() );
207+
mList << QgsPointLocator::Match( QgsPointLocator::Area, mLocator->mLayer, id, 0, mGeomPt.asPoint() );
208208
}
209209
private:
210210
QgsPointLocator *mLocator = nullptr;
@@ -908,7 +908,11 @@ QgsPointLocator::Match QgsPointLocator::nearestArea( const QgsPointXY &point, do
908908
return Match();
909909

910910
// use edges for adding tolerance
911-
return nearestEdge( point, tolerance, filter );
911+
Match m = nearestEdge( point, tolerance, filter );
912+
if ( m.isValid() )
913+
return Match( Area, m.layer(), m.featureId(), m.distance(), m.point() );
914+
else
915+
return Match();
912916
}
913917

914918

‎tests/src/core/testqgspointlocator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,16 @@ class TestQgsPointLocator : public QObject
144144
QCOMPARE( m2.layer(), mVL );
145145
QCOMPARE( m2.featureId(), ( QgsFeatureId )1 );
146146
QCOMPARE( m2.point(), QgsPointXY( 0.9, 0.9 ) );
147+
QCOMPARE( m2.distance(), 0 );
147148

148149
QgsPointXY pt3( 1.1, 1.1 );
149150
QgsPointLocator::Match m3 = loc.nearestArea( pt3, 999 );
150151
QVERIFY( m3.isValid() );
151152
QVERIFY( m3.hasArea() );
152153
QCOMPARE( m3.layer(), mVL );
153154
QCOMPARE( m3.featureId(), ( QgsFeatureId )1 );
154-
QCOMPARE( m3.point(), QgsPointXY( 1.0, 1 - 0 ) );
155+
QCOMPARE( m3.point(), QgsPointXY( 1.0, 1.0 ) );
156+
QCOMPARE( m3.distance(), .1 * std::sqrt( 2 ) );
155157
}
156158

157159
void testPointInPolygon()

0 commit comments

Comments
 (0)
Please sign in to comment.