Storing OGRPoint in Boost.Geometry rtree

I am trying to register OGR geometry classes with Boost.Geometry so I will eventually use them in Boost.Geometry RTree. To this end, I followed a tutorial / example in the Boost.Geometry documentation and registered OGRPoint with a macro BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET

:

BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(
    OGRPoint,
    double,
    boost::geometry::cs::spherical_equatorial<boost::geometry::degree>,
    getX,
    getY,
    setX,
    setY)

      

My simple test driver just creates an RTree with boost::geometry::model::box

Indexable:

typedef bg::model::box<OGRPoint> OGRBox;
typedef std::pair <OGRBox, unsigned> Value;

bgi::rtree<Value, bgi::rstar<16>> rtree;
OGRPoint testP0(12.0, 18.0),
        testP1(1.2, 1.8);

rtree.insert(std::make_pair(OGRBox(testP0, testP0), 0));
rtree.insert(std::make_pair(OGRBox(testP1, testP1), 1));

      

However, I am stuck with a compilation error that boils down to a statement in Boost:

../../../../include/boost/geometry/index/rtree.hpp:576:398: note:   cannot convert 'boost::geometry::index::rtree<Value, Options, IndexableGetter, EqualTo, Allocator>::insert(const Range&)::PASSED_OBJECT_IS_NOT_A_RANGE576::assert_arg<std::pair<boost::geometry::model::box<OGRPoint>, int> >()' (type 'mpl_::failed************ (boost::geometry::index::rtree<Value, Options, IndexableGetter, EqualTo, Allocator>::insert(const Range&) [with Range = std::pair<boost::geometry::model::box<OGRPoint>, int>; Value = std::pair<boost::geometry::model::box<OGRPoint>, unsigned int>; Parameters = boost::geometry::index::rstar<16ul>; IndexableGetter = boost::geometry::index::indexable<std::pair<boost::geometry::model::box<OGRPoint>, unsigned int> >; EqualTo = boost::geometry::index::equal_to<std::pair<boost::geometry::model::box<OGRPoint>, unsigned int> >; Allocator = std::allocator<std::pair<boost::geometry::model::box<OGRPoint>, unsigned int> >]::PASSED_OBJECT_IS_NOT_A_RANGE::************)(std::pair<boost::geometry::model::box<OGRPoint>, int>)') to type 'mpl_::assert<false>::type {aka mpl_::assert<false>}'
     BOOST_MPL_ASSERT_MSG((detail::is_range<Range>::value), PASSED_OBJECT_IS_NOT_A_RANGE, (Range));

      

Is there something else I need to do, such as execute Boost.Range for boost::geometry::model::box<OGRPoint>

?

+3


source to share


2 answers


This issue exists in Boost 1.56 and later.

There are 3 overloads rtree::insert()

:

rtree::insert(value_type const&)
rtree::insert(Iter first, Iter last)
rtree::insert(Range const&) // 1.56 and older

      

In Boost 1.56 and older, when an object of a type other than value_type

is passed into a member function insert()

, rtree treats it as a Range (an object of a type adapted to one of the Boost.Range concepts), An error message is generated at compile time when the parameter is not range.



In Boost 1.57, your code should work because the function now recognizes parameters being converted to value_type

. Now the third overload:

rtree::insert(ConvertibleOrRange const&) // 1.57

      

If you have any suggestions or find a bug, feel free to contact the developers on the mailing list or report a bug here .

+3


source


In this particular case, there were no errors with my adapter code. In fact, all this in the error message started with:

typedef std::pair <OGRBox, unsigned> Value;

      

Pay attention to unsigned

.

The error, however, indicates:



std::pair<boost::geometry::model::box<OGRPoint>, int>

      

Yes, . The solution is to use the constructor directly or add to the numeric literal like: int

std::pair<OGRBox, unsigned>

u

rtree.insert(std::make_pair(OGRBox(testP0, testP0), 0u));

      

I can't believe this just got me three hours of searching. Hope this helps someone.

+1


source







All Articles