Pau*_*l R 2 c++ boost iterator r-tree boost-geometry
我似乎找不到一种有效的方法来迭代一个boost R-tree(boost::geometry::index::rtree).到目前为止,我提出的唯一方法是使用非常大的边界框执行查询,以便在向量中返回所有元素的副本,但这显然既不节省空间也不节省时间.理想情况下,我只是想使用STL样式的迭代器以通常的方式迭代树,但这似乎不可能?
从1.59.0开始
begin()和end()成员函数定义bgi::rtree,返回一个const_iterator.因此,可以在没有下述技术的情况下迭代所有元素.在C++ 11中:
for(auto const& v: rtree)
/* do something with v */
Run Code Online (Sandbox Code Playgroud)
在1.59.0之前
正如其他人所说,迭代存储在rtree中的所有元素,您可以使用查询迭代器.但是,不需要执行实际的空间查询(传递边界等).你可以传递一个虚拟的UnaryPredicate总是返回true包裹着bgi::satisfies().在C++ 11中:
std::for_each(rtree.qbegin(bgi::satisfies([](Value const&){ return true; })),
rtree.qend(),
[](Value const& v){
/* do something with v */
});
Run Code Online (Sandbox Code Playgroud)
非迭代查询也可用于此目的,但它需要一个特殊的输出迭代器,例如boost::function_output_iterator在Boost.Iterator库中实现(参见http://www.boost.org/doc/libs/1_57_0/libs/iterator/ doc/function_output_iterator.html).在C++ 11中:
rtree.query(bgi::satisfies([](Value const&){ return true; }),
boost::make_function_output_iterator([](Value const& v){
/* do something with v */
}));
Run Code Online (Sandbox Code Playgroud)
附注:
namespace bgi = boost::geometry::indexValue 是一种存储在中的对象 bgi::rtreeboost::function_output_iterator 要求 #include <boost/function_output_iterator.hpp>