2014-04-07 2 views
1

여러 RTree 구현을 평가하려고하는데 boost::geometry::rtree::contains (부스트 버전 1.55)으로 문제가 발생했습니다. 내가하고있는 일은 점이 들어있는 모든 상자의 목록을 얻으려고하는 것입니다. 오른쪽 상자를 반환하지만 동일한 상자를 여러 번 반환합니다. 이유가 확실하지 않습니다. libspatialindex은이 작업을 수행하지 않습니다. 내가 확인되는 지점이 올바른지 확인했습니다boost :: geometry :: rtree :: contains 여러 개의 동일한 결과를 반환합니다.

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::vector 대신에 std::set을 사용하기 위해 반복자 faffery를하고 싶지도 않습니다.

* 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 

하지만 난 '분명 아무것도 찾을 수 없습니다 여기

은 일부 샘플 결과입니다 잘못하고있다.

+0

코드는 정상적으로 보입니다. 비록 내가 어떤 합성 데이터로 문제를 재현 할 수는 없지만. 내가 rtree에 5 개의 값만 저장한다고 가정합니까? 다각형 (점 및 ID)의 내용을 공유하면 도움이됩니다. –

답변

3

정확하게 rtree에 삽입 된 것을 쓰지 않았으므로 문제를 재현 할 수 없습니다.

현재 구현 된 버전의 rtree (Boost 1.55)에서는 삽입 한 모든 값에 대한 색인이 생성됩니다. 난 당신이 std :: multiset std :: set보다 더 작동한다고 생각할 수 있습니다. 따라서 어떤 이유로 인해 동일한 값이 생성되어 rtree에 삽입되면 출력에 중복이 있음을 알 수 있습니다.

+0

다른 구성 요소의 버그가 속임수를 삽입하고있었습니다. – James