Boost logo

Boost Users :

Subject: Re: [Boost-users] Interprenting nearest's neighbor's output
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2014-04-14 11:19:53


Hi Georgios,

Georgios Samaras wrote:
> I am running the code found here
> http://www.boost.org/doc/libs/1_54_0_beta1/libs/geometry/doc/html/geometry/spatial_indexes/rtree_examples/quick_start.html
>
> (not the intersect query, only the nn).
>
> The output is this:
> "
> knn query point:
> POINT(0 0)
> knn query result:
> POLYGON((4 4,4 4.5,4.5 4.5,4.5 4,4 4)) - 4
> POLYGON((3 3,3 3.5,3.5 3.5,3.5 3,3 3)) - 3
> POLYGON((2 2,2 2.5,2.5 2.5,2.5 2,2 2)) - 2
> POLYGON((0 0,0 0.5,0.5 0.5,0.5 0,0 0)) - 0
> POLYGON((1 1,1 1.5,1.5 1.5,1.5 1,1 1)) - 1
> "
>
> What are the integers on the right? Indices of the polygons?
> Actually is not really clear to me what are we inserting in the
> tree..I tried finding some documentation on these methods, but I only
> found info on how to call them...
>

In the rtree we're storing values defined in the line:

typedef std::pair<box, unsigned> value;

so it's a pair of a Box and some number. This is the classic approach
where in the spatial index you store AABB (Axis-Aligned Bounding Box) of
some geometry and an ID of this geometry.

So why Polygons are printed when you're storing Boxes? Those lines are
generated by this code:

std::cout << bg::wkt<box>(v.first) << " -" << v.second << std::endl;

First the Box is printed in WKT format, then " - " and the ID. But WKT
standard (http://en.wikipedia.org/wiki/Well-known_text) doesn't define
how Boxes should be described. Boost.Geometry uses WKT Polygons for
this. That's just a text output.

> What I want, is simply inserting some points in the tree and then
> search for nn of a query point.
>

If you don't need any additional data, instead of std::pair<box,
unsigned> just use point type from the same example.

Regards,
Adam


Boost-users 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