• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Iterative query</title>
5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../index.html" title="Chapter 1. Geometry">
8<link rel="up" href="../rtree_examples.html" title="Examples">
9<link rel="prev" href="range_adaptors.html" title="Range adaptors">
10<link rel="next" href="index_stored_in_shared_memory_using_boost_interprocess.html" title="Index stored in shared memory using Boost.Interprocess">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="range_adaptors.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rtree_examples.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="index_stored_in_shared_memory_using_boost_interprocess.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h4 class="title">
27<a name="geometry.spatial_indexes.rtree_examples.iterative_query"></a><a class="link" href="iterative_query.html" title="Iterative query">Iterative
28        query</a>
29</h4></div></div></div>
30<p>
31</p>
32<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
33<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">point</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
34<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">box</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
35
36<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">index</span><span class="special">/</span><span class="identifier">rtree</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
37
38<span class="comment">// just for output</span>
39<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
40
41<span class="keyword">namespace</span> <span class="identifier">bg</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">;</span>
42<span class="keyword">namespace</span> <span class="identifier">bgi</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">index</span><span class="special">;</span>
43
44<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
45<span class="special">{</span>
46    <span class="keyword">typedef</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">&gt;</span> <span class="identifier">point</span><span class="special">;</span>
47    <span class="keyword">typedef</span> <span class="identifier">point</span> <span class="identifier">value</span><span class="special">;</span>
48    <span class="keyword">typedef</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">rtree</span><span class="special">&lt;</span> <span class="identifier">value</span><span class="special">,</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">linear</span><span class="special">&lt;</span><span class="number">16</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">rtree_t</span><span class="special">;</span>
49
50    <span class="comment">// create the rtree using default constructor</span>
51    <span class="identifier">rtree_t</span> <span class="identifier">rtree</span><span class="special">;</span>
52
53    <span class="comment">// create some values</span>
54    <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">double</span> <span class="identifier">f</span> <span class="special">=</span> <span class="number">0</span> <span class="special">;</span> <span class="identifier">f</span> <span class="special">&lt;</span> <span class="number">10</span> <span class="special">;</span> <span class="identifier">f</span> <span class="special">+=</span> <span class="number">1</span> <span class="special">)</span>
55    <span class="special">{</span>
56        <span class="comment">// insert new value</span>
57        <span class="identifier">rtree</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">point</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">f</span><span class="special">));</span>
58    <span class="special">}</span>
59
60    <span class="comment">// query point</span>
61    <span class="identifier">point</span> <span class="identifier">pt</span><span class="special">(</span><span class="number">5.1</span><span class="special">,</span> <span class="number">5.1</span><span class="special">);</span>
62
63    <span class="comment">// iterate over nearest Values</span>
64    <span class="keyword">for</span> <span class="special">(</span> <span class="identifier">rtree_t</span><span class="special">::</span><span class="identifier">const_query_iterator</span>
65            <span class="identifier">it</span> <span class="special">=</span> <span class="identifier">rtree</span><span class="special">.</span><span class="identifier">qbegin</span><span class="special">(</span><span class="identifier">bgi</span><span class="special">::</span><span class="identifier">nearest</span><span class="special">(</span><span class="identifier">pt</span><span class="special">,</span> <span class="number">100</span><span class="special">))</span> <span class="special">;</span>
66            <span class="identifier">it</span> <span class="special">!=</span> <span class="identifier">rtree</span><span class="special">.</span><span class="identifier">qend</span><span class="special">()</span> <span class="special">;</span>
67            <span class="special">++</span><span class="identifier">it</span> <span class="special">)</span>
68    <span class="special">{</span>
69        <span class="keyword">double</span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">pt</span><span class="special">,</span> <span class="special">*</span><span class="identifier">it</span><span class="special">);</span>
70
71        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">wkt</span><span class="special">(*</span><span class="identifier">it</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="string">", distance= "</span> <span class="special">&lt;&lt;</span> <span class="identifier">d</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
72
73        <span class="comment">// break if the distance is too big</span>
74        <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">d</span> <span class="special">&gt;</span> <span class="number">2</span> <span class="special">)</span>
75        <span class="special">{</span>
76            <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"break!"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
77            <span class="keyword">break</span><span class="special">;</span>
78        <span class="special">}</span>
79    <span class="special">}</span>
80
81    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
82<span class="special">}</span>
83</pre>
84<p>
85        </p>
86<h5>
87<a name="geometry.spatial_indexes.rtree_examples.iterative_query.h0"></a>
88          <span class="phrase"><a name="geometry.spatial_indexes.rtree_examples.iterative_query.expected_results"></a></span><a class="link" href="iterative_query.html#geometry.spatial_indexes.rtree_examples.iterative_query.expected_results">Expected
89          results</a>
90        </h5>
91<pre class="programlisting"><span class="identifier">POINT</span><span class="special">(</span><span class="number">5</span> <span class="number">5</span><span class="special">),</span> <span class="identifier">distance</span><span class="special">=</span> <span class="number">0.141421</span>
92<span class="identifier">POINT</span><span class="special">(</span><span class="number">6</span> <span class="number">6</span><span class="special">),</span> <span class="identifier">distance</span><span class="special">=</span> <span class="number">1.27279</span>
93<span class="identifier">POINT</span><span class="special">(</span><span class="number">4</span> <span class="number">4</span><span class="special">),</span> <span class="identifier">distance</span><span class="special">=</span> <span class="number">1.55563</span>
94<span class="identifier">POINT</span><span class="special">(</span><span class="number">7</span> <span class="number">7</span><span class="special">),</span> <span class="identifier">distance</span><span class="special">=</span> <span class="number">2.68701</span>
95<span class="keyword">break</span><span class="special">!</span>
96</pre>
97</div>
98<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
99<td align="left"></td>
100<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
101      Wulkiewicz, Oracle and/or its affiliates<p>
102        Distributed under the Boost Software License, Version 1.0. (See accompanying
103        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
104      </p>
105</div></td>
106</tr></table>
107<hr>
108<div class="spirit-nav">
109<a accesskey="p" href="range_adaptors.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rtree_examples.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="index_stored_in_shared_memory_using_boost_interprocess.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
110</div>
111</body>
112</html>
113