C++ R - tree implementation wanted [closed]
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this questionDoes anyone know a good and simple to use in production code R-tree
implementation? (actually, any implementations - R*, R+
or PR-tree
would be great)
It doesn't matter if it is a template or library implementation, but some implementations that Google found look very disappointing...
You may also check out the rtree variants provided by the Boost.Geometry library:
http://www.boost.org/doc/libs/release/libs/geometry/doc/html/geometry/spatial_indexes.html
Boost.Geometry rtree implementation allows storing values of arbitrary type in the spatial index and performing complex queries. Parameters like maximum node elements may be passed as compile- or run-time parameters. It supports C++11 move semantics also emulated on pre-C++11 compilers thanks to Boost.Move. It also supports stateful allocators which allows e.g. to store the rtree in a shared memory using Boost.Interprocess. And it's fast.
On the down-side, currently persistent storage isn't yet supported so if you need more than in-memory spatial index you should probably check one of the other mentioned libraries.
Quick example:
Probably the most common use case is when you store some geometric objects in a container and their bounding boxes with some ids in the spatial index. In case of Boost.Geometry rtree this could look like this:
#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;
}
Check R-Trees code on http://www.superliminal.com/sources/sources.htm
also check
http://www.virtualroadside.com/blog/index.php/2008/10/04/r-tree-implementation-for-cpp/
I updated the implementation found in http://www.superliminal.com/sources/sources.htm to support a broader range of data types.
You can find my version on github: https://github.com/nushoin/RTree
The original version is public domain, as is mine.
spatialindex provides a nice interface to different types of spatial (and spatio-temporal) index structures including R, R*, TPR trees at http://libspatialindex.github.com/
精彩评论