@@ -110,10 +110,12 @@ static SpatialIndex::Region rect2region( const QgsRectangle& rect )
110
110
return SpatialIndex::Region ( pLow, pHigh, 2 );
111
111
}
112
112
113
+ #if 0
113
114
static QgsRectangle region2rect( const SpatialIndex::Region& region )
114
115
{
115
116
return QgsRectangle( region.m_pLow[0], region.m_pLow[1], region.m_pHigh[0], region.m_pHigh[1] );
116
117
}
118
+ #endif
117
119
118
120
static void addPolylineToEdgeData ( QLinkedList<RTree::Data*>& edgeDataList, const QgsPolyline& pl, id_type id, int & vertexIndex )
119
121
{
@@ -255,13 +257,14 @@ static void edgeGetEndpoints( const RTree::Data& dd, double&x1, double&y1, doubl
255
257
}
256
258
}
257
259
258
-
260
+ # if 0
259
261
static LineSegment edge2lineSegment( const RTree::Data& dd )
260
262
{
261
263
double pStart[2], pEnd[2];
262
264
edgeGetEndpoints( dd, pStart[0], pStart[1], pEnd[0], pEnd[1] );
263
265
return LineSegment( pStart, pEnd, 2 );
264
266
}
267
+ #endif
265
268
266
269
// Ahh.... another magic number. Taken from QgsVectorLayer::snapToGeometry() call to closestSegmentWithContext().
267
270
// The default epsilon used for sqrDistToSegment (1e-8) is too high when working with lat/lon coordinates
@@ -310,11 +313,11 @@ class QgsPointLocator_VisitorVertexEdge : public IVisitor
310
313
public:
311
314
// ! constructor for NN queries
312
315
QgsPointLocator_VisitorVertexEdge ( QgsVectorLayer* vl, bool vertexTree, const QgsPoint& origPt, QgsPointLocator::MatchList& list )
313
- : mLayer ( vl ), mVertexTree ( vertexTree ), mNNQuery ( true ), mOrigPt ( origPt ), mList ( list ) {}
316
+ : mLayer ( vl ), mVertexTree ( vertexTree ), mNNQuery ( true ), mOrigPt ( origPt ), mList ( list ), mDistToPoint ( 0 ), mFilter ( 0 ) {}
314
317
315
318
// ! constructor for range queries
316
- QgsPointLocator_VisitorVertexEdge ( QgsVectorLayer* vl, bool vertexTree, const QgsRectangle& origRect, QgsPointLocator::MatchList& list, const QgsPoint* distToPoint = 0 )
317
- : mLayer ( vl ), mVertexTree ( vertexTree ), mNNQuery ( false ), mOrigRect ( origRect ), mList ( list ), mDistToPoint ( distToPoint ) {}
319
+ QgsPointLocator_VisitorVertexEdge ( QgsVectorLayer* vl, bool vertexTree, const QgsRectangle& origRect, QgsPointLocator::MatchList& list, const QgsPoint* distToPoint = 0 , QgsPointLocator::MatchFilter* filter = 0 )
320
+ : mLayer ( vl ), mVertexTree ( vertexTree ), mNNQuery ( false ), mOrigRect ( origRect ), mList ( list ), mDistToPoint ( distToPoint ), mFilter ( filter ) {}
318
321
319
322
void visitNode ( const INode& n ) { Q_UNUSED ( n ); }
320
323
void visitData ( std::vector<const IData*>& v ) { Q_UNUSED ( v ); }
@@ -327,7 +330,7 @@ class QgsPointLocator_VisitorVertexEdge : public IVisitor
327
330
QgsPoint edgePoints[2 ];
328
331
if ( mNNQuery )
329
332
{
330
- // neirest neighbor query
333
+ // nearest neighbor query
331
334
if ( mVertexTree )
332
335
{
333
336
pt = QgsPoint ( dd.m_region .m_pLow [0 ], dd.m_region .m_pLow [1 ] );
@@ -372,7 +375,11 @@ class QgsPointLocator_VisitorVertexEdge : public IVisitor
372
375
}
373
376
QgsPointLocator::Type t = mVertexTree ? QgsPointLocator::Vertex : QgsPointLocator::Edge;
374
377
int vertexIndex = *reinterpret_cast <int *>( dd.m_pData );
375
- mList << QgsPointLocator::Match ( t, mLayer , d.getIdentifier (), dist, pt, vertexIndex, t == QgsPointLocator::Edge ? edgePoints : 0 );
378
+ QgsPointLocator::Match m ( t, mLayer , d.getIdentifier (), dist, pt, vertexIndex, t == QgsPointLocator::Edge ? edgePoints : 0 );
379
+ // in range queries the filter may reject some matches
380
+ if ( mFilter && !mFilter ->acceptMatch ( m ) )
381
+ return ;
382
+ mList << m;
376
383
}
377
384
378
385
private:
@@ -383,6 +390,7 @@ class QgsPointLocator_VisitorVertexEdge : public IVisitor
383
390
QgsRectangle mOrigRect ; // only for range queries
384
391
QgsPointLocator::MatchList& mList ;
385
392
const QgsPoint* mDistToPoint ; // optionally for range queries
393
+ QgsPointLocator::MatchFilter* mFilter ; // optionally for range queries
386
394
};
387
395
388
396
@@ -704,21 +712,21 @@ QgsPointLocator::MatchList QgsPointLocator::nearestEdges( const QgsPoint& point,
704
712
return lst;
705
713
}
706
714
707
- QgsPointLocator::MatchList QgsPointLocator::verticesInTolerance ( const QgsPoint& point, double tolerance )
715
+ QgsPointLocator::MatchList QgsPointLocator::verticesInTolerance ( const QgsPoint& point, double tolerance, MatchFilter* filter )
708
716
{
709
717
QgsRectangle rect ( point.x () - tolerance, point.y () - tolerance, point.x () + tolerance, point.y () + tolerance );
710
- MatchList lst = verticesInRect ( rect, &point );
718
+ MatchList lst = verticesInRect ( rect, &point, filter );
711
719
// make sure that only matches strictly within the tolerance are returned
712
720
// (the intersection with rect may yield matches outside of tolerance)
713
721
while ( !lst.isEmpty () && lst.last ().distance () > tolerance )
714
722
lst.removeLast ();
715
723
return lst;
716
724
}
717
725
718
- QgsPointLocator::MatchList QgsPointLocator::edgesInTolerance ( const QgsPoint& point, double tolerance )
726
+ QgsPointLocator::MatchList QgsPointLocator::edgesInTolerance ( const QgsPoint& point, double tolerance, MatchFilter* filter )
719
727
{
720
728
QgsRectangle rect ( point.x () - tolerance, point.y () - tolerance, point.x () + tolerance, point.y () + tolerance );
721
- MatchList lst = edgesInRect ( rect, &point );
729
+ MatchList lst = edgesInRect ( rect, &point, filter );
722
730
// make sure that only matches strictly within the tolerance are returned
723
731
// (the intersection with rect may yield matches outside of tolerance)
724
732
while ( !lst.isEmpty () && lst.last ().distance () > tolerance )
@@ -731,7 +739,7 @@ static bool matchDistanceLessThan( const QgsPointLocator::Match& m1, const QgsPo
731
739
return m1.distance () < m2.distance ();
732
740
}
733
741
734
- QgsPointLocator::MatchList QgsPointLocator::verticesInRect ( const QgsRectangle& rect, const QgsPoint* distToPoint )
742
+ QgsPointLocator::MatchList QgsPointLocator::verticesInRect ( const QgsRectangle& rect, const QgsPoint* distToPoint, MatchFilter* filter )
735
743
{
736
744
if ( !mRTreeVertex )
737
745
{
@@ -741,7 +749,7 @@ QgsPointLocator::MatchList QgsPointLocator::verticesInRect( const QgsRectangle&
741
749
}
742
750
743
751
MatchList lst;
744
- QgsPointLocator_VisitorVertexEdge visitor ( mLayer , true , rect, lst, distToPoint );
752
+ QgsPointLocator_VisitorVertexEdge visitor ( mLayer , true , rect, lst, distToPoint, filter );
745
753
mRTreeVertex ->intersectsWithQuery ( rect2region ( rect ), visitor );
746
754
747
755
// if there is no distToPoint, all distances are zero, so no need to sort
@@ -752,7 +760,7 @@ QgsPointLocator::MatchList QgsPointLocator::verticesInRect( const QgsRectangle&
752
760
}
753
761
754
762
755
- QgsPointLocator::MatchList QgsPointLocator::edgesInRect ( const QgsRectangle& rect, const QgsPoint* distToPoint )
763
+ QgsPointLocator::MatchList QgsPointLocator::edgesInRect ( const QgsRectangle& rect, const QgsPoint* distToPoint, MatchFilter* filter )
756
764
{
757
765
if ( !mRTreeEdge )
758
766
{
@@ -762,7 +770,7 @@ QgsPointLocator::MatchList QgsPointLocator::edgesInRect( const QgsRectangle& rec
762
770
}
763
771
764
772
MatchList lst;
765
- QgsPointLocator_VisitorVertexEdge visitor ( mLayer , false , rect, lst, distToPoint );
773
+ QgsPointLocator_VisitorVertexEdge visitor ( mLayer , false , rect, lst, distToPoint, filter );
766
774
mRTreeEdge ->intersectsWithQuery ( rect2region ( rect ), visitor );
767
775
768
776
// if there is no distToPoint, all distances are zero, so no need to sort
0 commit comments