我试图评估几个RTree实现,并且遇到了boost::geometry::rtree::contains (boost version 1.55)的一个问题。我要做的是得到一个包含点的所有框的列表。它返回正确的框,但返回相同的几次。我不知道为什么,libspatialindex不这么做。
这是我的密码:
void testBoostRTree(const Polygons& polygons)
{
using namespace boost::geometry;
typedef model::point<double, 2, cs::cartesian> BoostPoint;
typedef model::box<BoostPoint> BoostBox;
typedef model::polygon<BoostPoint, true, true> BoostPolygon; // clockwise, closed.
typedef std::pair<BoostBox, unsigned int> RTreeValue;
index::rtree<RTreeValue, index::rstar<16, 4>> rtree;
std::vector<BoostPoint> centrePoints;
for (const auto& p : polygons)
{
BoostPolygon bp;
for (const auto& point : p.m_points)
{
bp.outer().push_back(BoostPoint(point.first, point.second));
}
BoostBox box = return_envelope<BoostBox>(bp);
rtree.insert(std::make_pair(box, p.m_id));
centrePoints.push_back(return_centroid<BoostPoint>(box));
}
std::vector<RTreeValue> hits;
for (const auto& cp : centrePoints)
{
std::cout << "* Query point: " << get<0>(cp) << ", " << get<1>(cp) << "\n";
hits.clear();
rtree.query(index::contains(cp), std::back_inserter(hits));
for (const auto& r : hits)
{
std::cout << r.second << "\n";
}
}
}我已经证实被检查的点是正确的。我也不想为了使用std::set而不是std::vector而不得不使用迭代器。
以下是一些样本结果:
* Query point: 51.4181, 0.20462
278566
278566
278566
278566
278566
278566
261819
261821
261819
261820
261820
261821
13741
278566
278566
...将这些结果与libspatialindex的结果进行比较:
* Query 51.4181 0.20462
261819
261820
261821
13741
278566我已经浏览了文档和源代码,但没有发现任何明显的错误。
发布于 2014-04-22 10:49:10
由于您没有编写插入到rtree中的内容,所以我无法重现这个问题。
在当前实现的rtree版本(Boost 1.55)中,您插入的每个值都是索引的。我想您可能认为它更像std::multiset而不是std::set。因此,如果出于某种原因,生成相同的值并插入到rtree中,您可能会注意到输出中的重复项。
https://stackoverflow.com/questions/22920055
复制相似问题