3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>difference (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="../difference.html" title="difference">
9 <link rel="prev" href="../difference.html" title="difference">
10 <link rel="next" href="difference_3.html" title="difference">
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>
22 <div class="spirit-nav">
23 <a accesskey="p" href="../difference.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../difference.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="difference_3.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h5 class="title">
27 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy"></a><a class="link" href="difference_4_with_strategy.html" title="difference (with strategy)">difference
29 </h5></div></div></div>
31 <a class="indexterm" name="idm46187003664080"></a>
34 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h0"></a>
35 <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.description"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.description">Description</a>
38 Calculate the difference of two geometries
41 The free function difference calculates the spatial set theoretic difference
45 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h1"></a>
46 <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.synopsis"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.synopsis">Synopsis</a>
50 <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>
51 <span class="keyword">void</span> <span class="identifier">difference</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>
52 <span class="identifier">Strategy</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">strategy</span><span class="special">)</span></pre>
56 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h2"></a>
57 <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.parameters"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.parameters">Parameters</a>
59 <div class="informaltable"><table class="table">
97 Any type fulfilling a Geometry Concept
107 A model of the specified concept
114 Geometry2 const &
119 Any type fulfilling a Geometry Concept
129 A model of the specified concept
141 output collection, either a multi-geometry, or a std::vector<Geometry>
142 / std::deque<Geometry> etc
152 the output collection
164 Any type fulfilling a Difference Strategy Concept
174 The strategy which will be used for difference calculations
181 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h3"></a>
182 <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.header"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.header">Header</a>
188 <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>
194 <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="identifier">difference</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
197 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h4"></a>
198 <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.conformance"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.conformance">Conformance</a>
201 The function difference implements function Difference from the <a href="http://www.opengeospatial.org/standards/sfa" target="_top">OGC Simple Feature
205 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h5"></a>
206 <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.behavior"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.behavior">Behavior</a>
208 <div class="informaltable"><table class="table">
234 All combinations of: box, ring, polygon, multi_polygon
241 linear (e.g. linestring) / areal (e.g. polygon)
246 A combinations of a (multi) linestring with a (multi) polygon
247 results in a collection of linestrings
254 linear (e.g. linestring)
259 All combinations of: linestring, multi_linestring; results
260 in a collection of linestrings
267 pointlike (e.g. point)
272 All combinations of: point, multi_point; results in a collection
285 Not yet supported in this version
297 Not yet supported in this version
309 Not yet supported in this version
315 <div class="note"><table border="0" summary="Note">
317 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td>
318 <th align="left">Note</th>
320 <tr><td align="left" valign="top"><p>
321 Check the <a class="link" href="../../concepts/concept_polygon.html" title="Polygon Concept">Polygon
322 Concept</a> for the rules that polygon input for this algorithm
327 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h6"></a>
328 <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.example"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.example">Example</a>
331 Shows how to subtract one polygon from another polygon
335 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
336 <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">list</span><span class="special">></span>
338 <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>
339 <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>
340 <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>
342 <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>
345 <span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
346 <span class="special">{</span>
347 <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>
349 <span class="identifier">polygon</span> <span class="identifier">green</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">;</span>
351 <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>
352 <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>
353 <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>
355 <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>
356 <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>
358 <span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special"><</span><span class="identifier">polygon</span><span class="special">></span> <span class="identifier">output</span><span class="special">;</span>
359 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">difference</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>
361 <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
362 <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>
363 <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>
364 <span class="special">{</span>
365 <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>
366 <span class="special">}</span>
369 <span class="identifier">output</span><span class="special">.</span><span class="identifier">clear</span><span class="special">();</span>
370 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">difference</span><span class="special">(</span><span class="identifier">blue</span><span class="special">,</span> <span class="identifier">green</span><span class="special">,</span> <span class="identifier">output</span><span class="special">);</span>
372 <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
373 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"blue - green:"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
374 <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>
375 <span class="special">{</span>
376 <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>
377 <span class="special">}</span>
380 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
381 <span class="special">}</span>
388 <pre class="programlisting">green - blue:
395 <img src="../../../../img/algorithms/difference_a.png" alt="difference_a">
405 <img src="../../../../img/algorithms/difference_b.png" alt="difference_b">
408 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h7"></a>
409 <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.see_also"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.see_also">See
412 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
413 <li class="listitem">
414 <a class="link" href="../sym_difference.html" title="sym_difference">sym_difference
415 (symmetric difference)</a>
417 <li class="listitem">
418 <a class="link" href="../intersection.html" title="intersection">intersection</a>
420 <li class="listitem">
421 <a class="link" href="../union_.html" title="union_">union</a>
425 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
426 <td align="left"></td>
427 <td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
428 Wulkiewicz, Oracle and/or its affiliates<p>
429 Distributed under the Boost Software License, Version 1.0. (See accompanying
430 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>)
435 <div class="spirit-nav">
436 <a accesskey="p" href="../difference.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../difference.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="difference_3.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>