• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>union_</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="../union_.html" title="union_">
9<link rel="prev" href="union__4_with_strategy.html" title="union_ (with strategy)">
10<link rel="next" href="../unique.html" title="unique">
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="union__4_with_strategy.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../union_.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="../unique.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.union_.union__3"></a><a class="link" href="union__3.html" title="union_">union_</a>
28</h5></div></div></div>
29<p>
30            <a class="indexterm" name="idm45635687450704"></a>
31Combines two geometries which each other.
32          </p>
33<h6>
34<a name="geometry.reference.algorithms.union_.union__3.h0"></a>
35            <span class="phrase"><a name="geometry.reference.algorithms.union_.union__3.description"></a></span><a class="link" href="union__3.html#geometry.reference.algorithms.union_.union__3.description">Description</a>
36          </h6>
37<p>
38            The free function union calculates the spatial set theoretic union of
39            two geometries.
40          </p>
41<h6>
42<a name="geometry.reference.algorithms.union_.union__3.h1"></a>
43            <span class="phrase"><a name="geometry.reference.algorithms.union_.union__3.synopsis"></a></span><a class="link" href="union__3.html#geometry.reference.algorithms.union_.union__3.synopsis">Synopsis</a>
44          </h6>
45<p>
46</p>
47<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Geometry1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Geometry2</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Collection</span><span class="special">&gt;</span>
48<span class="keyword">void</span> <span class="identifier">union_</span><span class="special">(</span><span class="identifier">Geometry1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">geometry1</span><span class="special">,</span> <span class="identifier">Geometry2</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">geometry2</span><span class="special">,</span> <span class="identifier">Collection</span> <span class="special">&amp;</span> <span class="identifier">output_collection</span><span class="special">)</span></pre>
49<p>
50          </p>
51<h6>
52<a name="geometry.reference.algorithms.union_.union__3.h2"></a>
53            <span class="phrase"><a name="geometry.reference.algorithms.union_.union__3.parameters"></a></span><a class="link" href="union__3.html#geometry.reference.algorithms.union_.union__3.parameters">Parameters</a>
54          </h6>
55<div class="informaltable"><table class="table">
56<colgroup>
57<col>
58<col>
59<col>
60<col>
61</colgroup>
62<thead><tr>
63<th>
64                    <p>
65                      Type
66                    </p>
67                  </th>
68<th>
69                    <p>
70                      Concept
71                    </p>
72                  </th>
73<th>
74                    <p>
75                      Name
76                    </p>
77                  </th>
78<th>
79                    <p>
80                      Description
81                    </p>
82                  </th>
83</tr></thead>
84<tbody>
85<tr>
86<td>
87                    <p>
88                      Geometry1 const &amp;
89                    </p>
90                  </td>
91<td>
92                    <p>
93                      Any type fulfilling a Geometry Concept
94                    </p>
95                  </td>
96<td>
97                    <p>
98                      geometry1
99                    </p>
100                  </td>
101<td>
102                    <p>
103                      A model of the specified concept
104                    </p>
105                  </td>
106</tr>
107<tr>
108<td>
109                    <p>
110                      Geometry2 const &amp;
111                    </p>
112                  </td>
113<td>
114                    <p>
115                      Any type fulfilling a Geometry Concept
116                    </p>
117                  </td>
118<td>
119                    <p>
120                      geometry2
121                    </p>
122                  </td>
123<td>
124                    <p>
125                      A model of the specified concept
126                    </p>
127                  </td>
128</tr>
129<tr>
130<td>
131                    <p>
132                      Collection &amp;
133                    </p>
134                  </td>
135<td>
136                    <p>
137                      output collection, either a multi-geometry, or a std::vector&lt;Geometry&gt;
138                      / std::deque&lt;Geometry&gt; etc
139                    </p>
140                  </td>
141<td>
142                    <p>
143                      output_collection
144                    </p>
145                  </td>
146<td>
147                    <p>
148                      the output collection
149                    </p>
150                  </td>
151</tr>
152</tbody>
153</table></div>
154<h6>
155<a name="geometry.reference.algorithms.union_.union__3.h3"></a>
156            <span class="phrase"><a name="geometry.reference.algorithms.union_.union__3.header"></a></span><a class="link" href="union__3.html#geometry.reference.algorithms.union_.union__3.header">Header</a>
157          </h6>
158<p>
159            Either
160          </p>
161<p>
162            <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>
163          </p>
164<p>
165            Or
166          </p>
167<p>
168            <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="keyword">union</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
169          </p>
170<h6>
171<a name="geometry.reference.algorithms.union_.union__3.h4"></a>
172            <span class="phrase"><a name="geometry.reference.algorithms.union_.union__3.conformance"></a></span><a class="link" href="union__3.html#geometry.reference.algorithms.union_.union__3.conformance">Conformance</a>
173          </h6>
174<p>
175            The function union implements function Union from the <a href="http://www.opengeospatial.org/standards/sfa" target="_top">OGC
176            Simple Feature Specification</a>.
177          </p>
178<div class="note"><table border="0" summary="Note">
179<tr>
180<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td>
181<th align="left">Note</th>
182</tr>
183<tr><td align="left" valign="top"><p>
184              Boost.Geometry adds an underscore to avoid using the <code class="computeroutput"><span class="keyword">union</span></code> keyword
185            </p></td></tr>
186</table></div>
187<h6>
188<a name="geometry.reference.algorithms.union_.union__3.h5"></a>
189            <span class="phrase"><a name="geometry.reference.algorithms.union_.union__3.behavior"></a></span><a class="link" href="union__3.html#geometry.reference.algorithms.union_.union__3.behavior">Behavior</a>
190          </h6>
191<div class="informaltable"><table class="table">
192<colgroup>
193<col>
194<col>
195</colgroup>
196<thead><tr>
197<th>
198                    <p>
199                      Case
200                    </p>
201                  </th>
202<th>
203                    <p>
204                      Behavior
205                    </p>
206                  </th>
207</tr></thead>
208<tbody>
209<tr>
210<td>
211                    <p>
212                      GeometryOut is a Point
213                    </p>
214                  </td>
215<td>
216                    <p>
217                      Calculates union linestrings of input (multi)points
218                    </p>
219                  </td>
220</tr>
221<tr>
222<td>
223                    <p>
224                      GeometryOut is a Linestring
225                    </p>
226                  </td>
227<td>
228                    <p>
229                      Calculates union linestrings of input (multi)linestrings
230                    </p>
231                  </td>
232</tr>
233<tr>
234<td>
235                    <p>
236                      GeometryOut is a Polygon
237                    </p>
238                  </td>
239<td>
240                    <p>
241                      Calculates union polygons of input (multi)polygons and/or boxes
242                    </p>
243                  </td>
244</tr>
245</tbody>
246</table></div>
247<div class="note"><table border="0" summary="Note">
248<tr>
249<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td>
250<th align="left">Note</th>
251</tr>
252<tr><td align="left" valign="top"><p>
253              Check the <a class="link" href="../../concepts/concept_polygon.html" title="Polygon Concept">Polygon
254              Concept</a> for the rules that polygon input for this algorithm
255              should fulfill
256            </p></td></tr>
257</table></div>
258<h6>
259<a name="geometry.reference.algorithms.union_.union__3.h6"></a>
260            <span class="phrase"><a name="geometry.reference.algorithms.union_.union__3.example"></a></span><a class="link" href="union__3.html#geometry.reference.algorithms.union_.union__3.example">Example</a>
261          </h6>
262<p>
263            Shows how to get a united geometry of two polygons
264          </p>
265<p>
266</p>
267<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
268<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
269
270<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>
271<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>
272<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">polygon</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
273
274<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">foreach</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
275
276
277<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
278<span class="special">{</span>
279    <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">polygon</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">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="special">&gt;</span> <span class="identifier">polygon</span><span class="special">;</span>
280
281    <span class="identifier">polygon</span> <span class="identifier">green</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">;</span>
282
283    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">read_wkt</span><span class="special">(</span>
284        <span class="string">"POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"</span>
285            <span class="string">"(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))"</span><span class="special">,</span> <span class="identifier">green</span><span class="special">);</span>
286
287    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">read_wkt</span><span class="special">(</span>
288        <span class="string">"POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5))"</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">);</span>
289
290    <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">polygon</span><span class="special">&gt;</span> <span class="identifier">output</span><span class="special">;</span>
291    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">union_</span><span class="special">(</span><span class="identifier">green</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">,</span> <span class="identifier">output</span><span class="special">);</span>
292
293    <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
294    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"green || blue:"</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>
295    <span class="identifier">BOOST_FOREACH</span><span class="special">(</span><span class="identifier">polygon</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">output</span><span class="special">)</span>
296    <span class="special">{</span>
297        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">i</span><span class="special">++</span> <span class="special">&lt;&lt;</span> <span class="string">": "</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">area</span><span class="special">(</span><span class="identifier">p</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>
298    <span class="special">}</span>
299
300
301    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
302<span class="special">}</span>
303</pre>
304<p>
305          </p>
306<p>
307            Output:
308          </p>
309<pre class="programlisting">green || blue:
3100: 5.64795
311
312<img src="../../../../img/algorithms/union.png" alt="union">
313
314</pre>
315<h6>
316<a name="geometry.reference.algorithms.union_.union__3.h7"></a>
317            <span class="phrase"><a name="geometry.reference.algorithms.union_.union__3.see_also"></a></span><a class="link" href="union__3.html#geometry.reference.algorithms.union_.union__3.see_also">See
318            also</a>
319          </h6>
320<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
321<li class="listitem">
322                <a class="link" href="../intersection.html" title="intersection">intersection</a>
323              </li>
324<li class="listitem">
325                <a class="link" href="../difference.html" title="difference">difference</a>
326              </li>
327<li class="listitem">
328                <a class="link" href="../sym_difference.html" title="sym_difference">sym_difference
329                (symmetric difference)</a>
330              </li>
331</ul></div>
332</div>
333<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
334<td align="left"></td>
335<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
336      Wulkiewicz, Oracle and/or its affiliates<p>
337        Distributed under the Boost Software License, Version 1.0. (See accompanying
338        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>)
339      </p>
340</div></td>
341</tr></table>
342<hr>
343<div class="spirit-nav">
344<a accesskey="p" href="union__4_with_strategy.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../union_.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="../unique.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
345</div>
346</body>
347</html>
348