Jepessen
Jepessen

Reputation: 12415

Calculate intersections between rtrees

I was following the boost geometry rtree documentation. I'm able to perform a spatial query with a box in order to retrieve the list of rtree elements that intersect with it.

I'd like to know if there's a way to perform a spatial query between an rtree and another rtree (of the same type).

Something like:

typedef bg::model::point<float, 2, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
typedef std::pair<box, unsigned> value;

bgi::rtree< value, bgi::quadratic<16> > rtree1;
//... create first rtree
bgi::rtree< value, bgi::quadratic<16> > rtree2;
//... create second rtree
std::vector<value> result_s;
rtree1.query(bgi::intersects(rtree2), std::back_inserter(result_s));
// At this point result_s should contain elements of rtree1 that intersect with rtree2

Is is possible something like that or I can only perform query with elements of the same type of rtree template elements?

Upvotes: 0

Views: 547

Answers (1)

TilmannZ
TilmannZ

Reputation: 1889

I think what you mean is called a 'spatial join'. The naive approach would iterate through all element of the smaller tree and perform rectangle queries on the larger tree. There is some research about this, just search scholar.google.com for 'spatial join'.

I don't think any of the advanced approaches are significantly better than the naive approach that I described above, but I'm not up to date with that topic.

Upvotes: 2

Related Questions