boost::geometry: nearest neighbors using a circle

前端 未结 2 1750
借酒劲吻你
借酒劲吻你 2020-12-15 09:46

I am using the Rtree implementation of boost::geometry to store (lots of) 2D points. Now I need to do distance-based nearest neigbors queries.

However, the manual on

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 10:32

    The manual documents some model::ring class that I thought at first might fit for a circle, but it is actually more a kind of a piece-wise line (a polygon). Is that assumption correct ?

    I think that's correct.

    I noticed that you can define a unary-predicate, but is is... unary (thus, not suitable for a condition on two points).

    Would the 'second' (or reference) point not be fixed? Because then you can use a simple bind expression to supply the reference point.


    Additionally you can use the KNN algorithm with a very large n and add some kind of breaking condition on the predicate:

    Breaking or pausing the query

    for ( Rtree::const_query_iterator it = tree.qbegin(bgi::nearest(pt, 10000)) ;
          it != tree.qend() ; ++it )
    {
        // do something with value
        if ( has_enough_nearest_values() )
            break;
    }
    

    This could work pretty well, assuming that the algorithm already traverses the points in order of ascending distance (you will want to check that assumption of course).

提交回复
热议问题