Boost logo

Geometry :

Subject: Re: [geometry] R-tree segment query optimization
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2018-04-16 16:49:06


Hi Jeremy,

Jeremy Murphy wrote:
> Hi Adam,
>
> thanks for the detailed answer. I haven't used Boost.Geometry rtree in
> a while, so I'm stuck already.  :\
> I created an rtree of 2D Cartesian points, that's fine. But when I
> tried to do a query using a nearest(segment, 1) predicate, I get a
> compilation error that looks like comparable_distance is
> not-yet-implemented between SEGMENT and BOX.
>
<snip>

> Did I use it incorrectly or is it actually just not yet supported? I'm
> using the head of develop.

It is supported. It's hard to tell what may be the problem in your case
without the code. The following code compiles and runs correctly for me:

#include <boost/geometry.hpp>
#include <boost/geometry/index/rtree.hpp>

#include <iostream>
#include <vector>

namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;

int main()
{
 Â Â Â  typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
 Â Â Â  typedef bg::model::box<point_t> box_t;
 Â Â Â  typedef bg::model::segment<point_t> segment_t;
 Â Â Â  typedef bg::model::referring_segment<point_t> ref_segment_t;

 Â Â Â  bgi::rtree<point_t, bgi::rstar<4> > rt;

 Â Â Â  for (double x = 0 ; x < 10 ; x += 2)
 Â Â Â Â Â Â Â  for (double y = 0 ; y < 10 ; y += 2)
 Â Â Â Â Â Â Â Â Â Â Â  rt.insert(point_t{x, y});

 Â Â Â  point_t res;
 Â Â Â  segment_t seg{{1, 1},{3, 1}};
 Â Â Â  ref_segment_t ref_seg{seg.first, seg.second};

 Â Â Â  size_t f = rt.query(bgi::nearest(seg, 1), &res);
 Â Â Â  if (f > 0)
 Â Â Â Â Â Â Â  std::cout << bg::wkt(res) << std::endl;

 Â Â Â  f = rt.query(bgi::nearest(ref_seg, 1), &res);
 Â Â Â  if (f > 0)
 Â Â Â Â Â Â Â  std::cout << bg::wkt(res) << std::endl;

 Â Â Â  bg::comparable_distance(segment_t(), point_t());
 Â Â Â  bg::comparable_distance(point_t(), segment_t());
 Â Â Â  bg::comparable_distance(segment_t(), box_t());
 Â Â Â  bg::comparable_distance(box_t(), segment_t());
}

Adam



Geometry list run by mateusz at loskot.net