我正在尝试评估几个 RTree 实现并遇到了一个问题boost::geometry::rtree::contains
(提升版本 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
我已经搜索了文档和源代码,但我找不到任何明显的错误。