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