
Boost Users : 
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 20191014 17:23:28
Hi,
W dniu 14.10.2019 oÂ 16:57, vexakul via Boostusers pisze:
> Hi all!
>
> I need to store geographic points in rtree and be able to answer nearest
> query.
>
> Can someone provide an example similar to this
> <https://www.boost.org/doc/libs/1_65_1/libs/geometry/doc/html/geometry/spatial_indexes/rtree_examples/quick_start.html>
> but with point type bg::model::point<float, 2,
> bg::cs::geographic<bg::degree>>? Is that supported? For me it fails to
> compile.
When you define the geographic point as Rtree element type the
computation should be done in geographic CS by default using WGS84
ellipsoid and andoyer formula to calculate distances. So simply:
using boost::geometry;
using point = model::point<double, 2, cs::geographic<degree>>;
using rtree = index::rtree<point, index::rstar<4>>;
rtree rt;
// or
std::vector<point> pts;
rtree rt2{pts.begin(), pts.end()};
If you need different ellipsoid or more accurate formula it is also
possible (since Boost 1.71) though it is not documented. It's because
I'm not entirely sure what to do with the fact that with this approach
the EqualTo is called with two or three arguments depending on the
parameters passed into the Rtree so it may be confusing. So there is
slight probability that the interface will change in case I found some
better way of defining CSspecific parts of the computation. So if you
e.g. need to pass a different ellipsoid you can wrap the Rtree
parameters together with Index strategy and pass it into the Rtree like
that:
using boost::geometry;
using formula = strategy::andoyer;// or more accurate strategy::vincenty
srs::spheroid<double> sph(6378137.0, 6356752.3142451793);
using point = model::point<double, 2, cs::geographic<degree>>;
using parameters = index::parameters
Â Â Â <
Â Â Â Â Â Â Â index::rstar<4>,
Â Â Â Â Â strategy::index::geographic<formula>
Â Â Â >;
using rtree = index::rtree<point, parameters>;
rtree rt{parameters{index::rstar<4>{},
strategy::index::geographic<formula>{sph}}};
// or
std::vector<point> pts;
rtree rt2{pts.begin(), pts.end(),
parameters{index::rstar<4>{},
strategy::index::geographic<formula>{sph}}};
Have in mind that I didn't test the code above so there may be some
mistakes.
Adam
Boostusers list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net