]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry Index |
2 | // | |
3 | // Quickbook Examples | |
4 | // | |
5 | // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland. | |
6 | // | |
7 | // Use, modification and distribution is subject to the Boost Software License, | |
8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
9 | // http://www.boost.org/LICENSE_1_0.txt) | |
10 | ||
11 | //[rtree_iterative_query | |
12 | ||
13 | #include <boost/geometry.hpp> | |
14 | #include <boost/geometry/geometries/point.hpp> | |
15 | #include <boost/geometry/geometries/box.hpp> | |
16 | ||
17 | #include <boost/geometry/index/rtree.hpp> | |
18 | ||
19 | // just for output | |
20 | #include <iostream> | |
21 | ||
22 | namespace bg = boost::geometry; | |
23 | namespace bgi = boost::geometry::index; | |
24 | ||
25 | int main() | |
26 | { | |
27 | typedef bg::model::point<double, 2, bg::cs::cartesian> point; | |
28 | typedef point value; | |
29 | typedef bgi::rtree< value, bgi::linear<16> > rtree_t; | |
30 | ||
31 | // create the rtree using default constructor | |
32 | rtree_t rtree; | |
33 | ||
34 | // create some values | |
35 | for ( double f = 0 ; f < 10 ; f += 1 ) | |
36 | { | |
37 | // insert new value | |
38 | rtree.insert(point(f, f)); | |
39 | } | |
40 | ||
41 | // query point | |
42 | point pt(5.1, 5.1); | |
43 | ||
44 | // iterate over nearest Values | |
45 | for ( rtree_t::const_query_iterator | |
46 | it = rtree.qbegin(bgi::nearest(pt, 100)) ; | |
47 | it != rtree.qend() ; | |
48 | ++it ) | |
49 | { | |
50 | double d = bg::distance(pt, *it); | |
51 | ||
52 | std::cout << bg::wkt(*it) << ", distance= " << d << std::endl; | |
53 | ||
54 | // break if the distance is too big | |
55 | if ( d > 2 ) | |
56 | { | |
57 | std::cout << "break!" << std::endl; | |
58 | break; | |
59 | } | |
60 | } | |
61 | ||
62 | return 0; | |
63 | } | |
64 | ||
65 | //] |