-
Hi, this might be already obvious but I would like a bit of clarity on the documentation of the query iterators.
When using the iterators for Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
With query iterators taking With Is that explanation clear? |
Beta Was this translation helpful? Give feedback.
-
Sorry, I meant to ask for using query |
Beta Was this translation helpful? Give feedback.
-
Yes, the answer is no. :) Unless I'm missing something. Do you have a case where you'd like to sort the elements somehow? An example perhaps? |
Beta Was this translation helpful? Give feedback.
-
Thanks! 😄 My use case right now is to find intersection between a point and an RTree of boxes, but have the intersecting boxes be sorted by ascending distance (from point). I guess the best way is to post-sort them then. |
Beta Was this translation helpful? Give feedback.
-
In general, yes, if you need all of the objects, not Have in mind that you'd achieve the same outcome if you used query iterator with In your particular case I don't understand how the sorting would work because if a point intersects a box then the distance from this point to the box is |
Beta Was this translation helpful? Give feedback.
-
You're right, sorry I didn't explain properly. There is an R-Tree of boxes that represent geometries. I am trying to find all geometries that intersect a search box, and is within some distance from a point. This point is the center of the larger box. I am achieving this by: Box search_box = ...;
double max_distance = ...;
const auto it = rtree.qbegin(intersects(search_box) && satisfies([max_distance](const std::pair<Box, Object>& pair) {
return distance(pair.second, point) < max_distance;
}));
// Unsorted
std::vector<Object> objects;
for (; it != rtree.qend(); ++id)
{
objects.push_back(it->second);
}
// Then sort by recomputing distances from point to Object I'm guessing this is the fastest way? |
Beta Was this translation helpful? Give feedback.
-
Ok, so I see you're storing some Objects in the R-tree and then using query iterator in order to get all of the elements of the query at once. Depending how big the Object is it is ok to store them in the R-tree or not. It's because Values stored in the R-tree can be copied during The second thing is that if you want to get all of the objects in the intersecting region (e.g. you do not want to break the query somewhere in the middle) then it would be faster to call So it'd be something like this (without Boost.Range adaptors and
[1] https://www.boost.org/doc/libs/1_74_0/libs/geometry/doc/html/geometry/spatial_indexes/rtree_examples/range_adaptors.html |
Beta Was this translation helpful? Give feedback.
-
Thanks! Good to know |
Beta Was this translation helpful? Give feedback.
Ok, so I see you're storing some Objects in the R-tree and then using query iterator in order to get all of the elements of the query at once.
Depending how big the Object is it is ok to store them in the R-tree or not. It's because Values stored in the R-tree can be copied during
insert()
, tree creation in general or when values are returned by thequery()
method. So if Objects are e.g. polygons it would be better to store them in e.g. a separate container and then in the R-tree store pairs of bounding boxes of polygons with IDs of polygons (index in a vector, iterator in a set, etc.). You could use Boost.Range adaptors to avoid intermediate step of creating a container of R-tree element…