• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>simplify</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="../simplify.html" title="simplify">
9<link rel="prev" href="simplify_4_with_strategy.html" title="simplify (with strategy)">
10<link rel="next" href="../sym_difference.html" title="sym_difference">
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="simplify_4_with_strategy.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../simplify.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="../sym_difference.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h5 class="title">
27<a name="geometry.reference.algorithms.simplify.simplify_3"></a><a class="link" href="simplify_3.html" title="simplify">simplify</a>
28</h5></div></div></div>
29<p>
30            <a class="indexterm" name="idm45635689149744"></a>
31Simplify a geometry.
32          </p>
33<h6>
34<a name="geometry.reference.algorithms.simplify.simplify_3.h0"></a>
35            <span class="phrase"><a name="geometry.reference.algorithms.simplify.simplify_3.synopsis"></a></span><a class="link" href="simplify_3.html#geometry.reference.algorithms.simplify.simplify_3.synopsis">Synopsis</a>
36          </h6>
37<p>
38</p>
39<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Geometry</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Distance</span><span class="special">&gt;</span>
40<span class="keyword">void</span> <span class="identifier">simplify</span><span class="special">(</span><span class="identifier">Geometry</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">geometry</span><span class="special">,</span> <span class="identifier">Geometry</span> <span class="special">&amp;</span> <span class="identifier">out</span><span class="special">,</span> <span class="identifier">Distance</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">max_distance</span><span class="special">)</span></pre>
41<p>
42          </p>
43<h6>
44<a name="geometry.reference.algorithms.simplify.simplify_3.h1"></a>
45            <span class="phrase"><a name="geometry.reference.algorithms.simplify.simplify_3.parameters"></a></span><a class="link" href="simplify_3.html#geometry.reference.algorithms.simplify.simplify_3.parameters">Parameters</a>
46          </h6>
47<div class="informaltable"><table class="table">
48<colgroup>
49<col>
50<col>
51<col>
52<col>
53</colgroup>
54<thead><tr>
55<th>
56                    <p>
57                      Type
58                    </p>
59                  </th>
60<th>
61                    <p>
62                      Concept
63                    </p>
64                  </th>
65<th>
66                    <p>
67                      Name
68                    </p>
69                  </th>
70<th>
71                    <p>
72                      Description
73                    </p>
74                  </th>
75</tr></thead>
76<tbody>
77<tr>
78<td>
79                    <p>
80                      Geometry const &amp;
81                    </p>
82                  </td>
83<td>
84                    <p>
85                      Any type fulfilling a Geometry Concept
86                    </p>
87                  </td>
88<td>
89                    <p>
90                      geometry
91                    </p>
92                  </td>
93<td>
94                    <p>
95                      input geometry, to be simplified
96                    </p>
97                  </td>
98</tr>
99<tr>
100<td>
101                    <p>
102                      Geometry &amp;
103                    </p>
104                  </td>
105<td>
106                    <p>
107                      Any type fulfilling a Geometry Concept
108                    </p>
109                  </td>
110<td>
111                    <p>
112                      out
113                    </p>
114                  </td>
115<td>
116                    <p>
117                      output geometry, simplified version of the input geometry
118                    </p>
119                  </td>
120</tr>
121<tr>
122<td>
123                    <p>
124                      Distance const &amp;
125                    </p>
126                  </td>
127<td>
128                    <p>
129                      numerical type (int, double, ttmath, ...)
130                    </p>
131                  </td>
132<td>
133                    <p>
134                      max_distance
135                    </p>
136                  </td>
137<td>
138                    <p>
139                      distance (in units of input coordinates) of a vertex to other
140                      segments to be removed
141                    </p>
142                  </td>
143</tr>
144</tbody>
145</table></div>
146<h6>
147<a name="geometry.reference.algorithms.simplify.simplify_3.h2"></a>
148            <span class="phrase"><a name="geometry.reference.algorithms.simplify.simplify_3.header"></a></span><a class="link" href="simplify_3.html#geometry.reference.algorithms.simplify.simplify_3.header">Header</a>
149          </h6>
150<p>
151            Either
152          </p>
153<p>
154            <code class="computeroutput"><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></code>
155          </p>
156<p>
157            Or
158          </p>
159<p>
160            <code class="computeroutput"><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">algorithms</span><span class="special">/</span><span class="identifier">simplify</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
161          </p>
162<h6>
163<a name="geometry.reference.algorithms.simplify.simplify_3.h3"></a>
164            <span class="phrase"><a name="geometry.reference.algorithms.simplify.simplify_3.conformance"></a></span><a class="link" href="simplify_3.html#geometry.reference.algorithms.simplify.simplify_3.conformance">Conformance</a>
165          </h6>
166<p>
167            The function simplify is not defined by OGC.
168          </p>
169<div class="note"><table border="0" summary="Note">
170<tr>
171<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td>
172<th align="left">Note</th>
173</tr>
174<tr><td align="left" valign="top"><p>
175              PostGIS contains an algorithm with the same name and the same functionality.
176              See the <a href="http://www.postgis.org/docs/ST_Simplify.html" target="_top">PostGIS
177              documentation</a>.
178            </p></td></tr>
179</table></div>
180<div class="note"><table border="0" summary="Note">
181<tr>
182<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td>
183<th align="left">Note</th>
184</tr>
185<tr><td align="left" valign="top"><p>
186              SQL Server contains an algorithm Reduce() with the same functionality.
187              See the <a href="http://msdn.microsoft.com/en-us/library/bb933814.aspx" target="_top">MSDN
188              documentation</a>.
189            </p></td></tr>
190</table></div>
191<h6>
192<a name="geometry.reference.algorithms.simplify.simplify_3.h4"></a>
193            <span class="phrase"><a name="geometry.reference.algorithms.simplify.simplify_3.behavior"></a></span><a class="link" href="simplify_3.html#geometry.reference.algorithms.simplify.simplify_3.behavior">Behavior</a>
194          </h6>
195<p>
196            Simplification is done using <a href="http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm" target="_top">Douglas-Peucker</a>
197            (if the default strategy is used).
198          </p>
199<div class="note"><table border="0" summary="Note">
200<tr>
201<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td>
202<th align="left">Note</th>
203</tr>
204<tr><td align="left" valign="top"><p>
205              Geometries might become invalid by using simplify. The simplification
206              process might create self-intersections.
207            </p></td></tr>
208</table></div>
209<h6>
210<a name="geometry.reference.algorithms.simplify.simplify_3.h5"></a>
211            <span class="phrase"><a name="geometry.reference.algorithms.simplify.simplify_3.examples"></a></span><a class="link" href="simplify_3.html#geometry.reference.algorithms.simplify.simplify_3.examples">Examples</a>
212          </h6>
213<p>
214            Example showing how to simplify a linestring
215          </p>
216<p>
217</p>
218<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
219
220<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>
221<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">linestring</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
222<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_xy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
223
224<a class="co" name="geometry.reference.algorithms.simplify.simplify_3.c0" href="simplify_3.html#geometry.reference.algorithms.simplify.simplify_3.c1"><img src="../../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a>
225<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">assign</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
226
227<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">assign</span><span class="special">;</span>
228
229
230<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
231<span class="special">{</span>
232    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">d2</span><span class="special">::</span><span class="identifier">point_xy</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">xy</span><span class="special">;</span>
233
234    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">linestring</span><span class="special">&lt;</span><span class="identifier">xy</span><span class="special">&gt;</span> <span class="identifier">line</span><span class="special">;</span>
235    <span class="identifier">line</span> <span class="special">+=</span> <span class="identifier">xy</span><span class="special">(</span><span class="number">1.1</span><span class="special">,</span> <span class="number">1.1</span><span class="special">),</span> <span class="identifier">xy</span><span class="special">(</span><span class="number">2.5</span><span class="special">,</span> <span class="number">2.1</span><span class="special">),</span> <span class="identifier">xy</span><span class="special">(</span><span class="number">3.1</span><span class="special">,</span> <span class="number">3.1</span><span class="special">),</span> <span class="identifier">xy</span><span class="special">(</span><span class="number">4.9</span><span class="special">,</span> <span class="number">1.1</span><span class="special">),</span> <span class="identifier">xy</span><span class="special">(</span><span class="number">3.1</span><span class="special">,</span> <span class="number">1.9</span><span class="special">);</span> <a class="co" name="geometry.reference.algorithms.simplify.simplify_3.c2" href="simplify_3.html#geometry.reference.algorithms.simplify.simplify_3.c3"><img src="../../../../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a>
236
237    <span class="comment">// Simplify it, using distance of 0.5 units</span>
238    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">linestring</span><span class="special">&lt;</span><span class="identifier">xy</span><span class="special">&gt;</span> <span class="identifier">simplified</span><span class="special">;</span>
239    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">simplify</span><span class="special">(</span><span class="identifier">line</span><span class="special">,</span> <span class="identifier">simplified</span><span class="special">,</span> <span class="number">0.5</span><span class="special">);</span>
240    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
241        <span class="special">&lt;&lt;</span> <span class="string">"  original: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">dsv</span><span class="special">(</span><span class="identifier">line</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span>
242        <span class="special">&lt;&lt;</span> <span class="string">"simplified: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">dsv</span><span class="special">(</span><span class="identifier">simplified</span><span class="special">)</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>
243
244
245    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
246<span class="special">}</span>
247</pre>
248<p>
249          </p>
250<div class="calloutlist"><table border="0" summary="Callout list">
251<tr>
252<td width="5%" valign="top" align="left"><p><a name="geometry.reference.algorithms.simplify.simplify_3.c1"></a><a href="#geometry.reference.algorithms.simplify.simplify_3.c0"><img src="../../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
253<td valign="top" align="left"><p>
254                For this example we use Boost.Assign to add points
255              </p></td>
256</tr>
257<tr>
258<td width="5%" valign="top" align="left"><p><a name="geometry.reference.algorithms.simplify.simplify_3.c3"></a><a href="#geometry.reference.algorithms.simplify.simplify_3.c2"><img src="../../../../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td>
259<td valign="top" align="left"><p>
260                With Boost.Assign
261              </p></td>
262</tr>
263</table></div>
264<p>
265            Output:
266          </p>
267<pre class="programlisting">original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
268simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
269</pre>
270<h6>
271<a name="geometry.reference.algorithms.simplify.simplify_3.h6"></a>
272            <span class="phrase"><a name="geometry.reference.algorithms.simplify.simplify_3.image_s_"></a></span><a class="link" href="simplify_3.html#geometry.reference.algorithms.simplify.simplify_3.image_s_">Image(s)</a>
273          </h6>
274<p>
275            <span class="inlinemediaobject"><img src="../../../../svg_simplify_country.png" alt="svg_simplify_country"></span>
276          </p>
277</div>
278<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
279<td align="left"></td>
280<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
281      Wulkiewicz, Oracle and/or its affiliates<p>
282        Distributed under the Boost Software License, Version 1.0. (See accompanying
283        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>)
284      </p>
285</div></td>
286</tr></table>
287<hr>
288<div class="spirit-nav">
289<a accesskey="p" href="simplify_4_with_strategy.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../simplify.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="../sym_difference.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
290</div>
291</body>
292</html>
293