有人知道在生产代码中使用良好且易于使用吗 R-tree 执行? (实际上,任何实现 - R*, R+ 或者 PR-tree 会很好)

它是模板还是库实现都没关系,但是Google发现的某些实现看起来非常令人失望...

其他提示

您也可以查看BOOST。几何库提供的RTREE变体:

http://www.boost.org/doc/libs/release/libs/geometry/doc/html/geometry/spatial_indexes.html

BOOST。几何RTREE实现允许将任意类型的值存储在空间索引中并执行复杂的查询。可以将最大节点元素(例如最大节点元素)作为编译或运行时参数传递。它支持C ++ 11 MOVE SEMANTS,还可以在Pre-C ++ 11编译器上模仿,这要归功于BOOST.MOVE。它还支持状态分配器,例如,EG可以使用boost.interprocess将RTREE存储在共享内存中。而且很快。

在下边,目前尚未支持当前的持续存储,因此,如果您需要更多的内存空间索引,则可能应该检查其他提到的库之一。

快速示例:

可能最常见的用例是,当您将一些几何对象存储在容器及其边界框中时,并在空间索引中使用一些ID。如果是boost。几何rtree,这可能是这样的:

#include <boost/geometry.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <vector>

namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;

/* The definition of my_object type goes here */

int main()
{
    typedef bg::model::point<float, 2, bg::cs::cartesian> point;
    typedef bg::model::box<point> box;
    typedef std::pair<box, size_t> value;

    std::vector<my_object> objects;

    /* Fill objects */

    // create the R* variant of the rtree
    bgi::rtree< value, bgi::rstar<16> > rtree;

    // insert some values to the rtree
    for ( size_t i = 0 ; i < objects.size() ; ++i )
    {
        // create a box
        box b = objects[i].calculate_bounding_box();
        // insert new value
        rtree.insert(std::make_pair(b, i));
    }

    // find values intersecting some area defined by a box
    box query_box(point(0, 0), point(5, 5));
    std::vector<value> result_s;
    rtree.query(bgi::intersects(query_box), std::back_inserter(result_s));

    // find 5 nearest values to a point
    std::vector<value> result_n;
    rtree.query(bgi::nearest(point(0, 0), 5), std::back_inserter(result_n));

    return 0;
}

我更新了在 http://www.superliminal.com/sources/sources.htm 支持更广泛的数据类型。

您可以在GitHub上找到我的版本: https://github.com/nushoin/rtree

原始版本是公共领域,就像我的。

空间indexex为不同类型的空间(和时空)索引结构提供了一个不错的接口,包括R,R*,TPR树 http://libspatialindex.github.com/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top