Boost C++ Libraries: Ticket #9733: boost::geometry::intersection fails https://svn.boost.org/trac10/ticket/9733 <p> I expect this has something to do with floating-point tolerances. This bug appears to be similar to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6958" title="#6958: Bugs: boost::geometry::intersection on two polygons creates ... (closed: fixed)">#6958</a> (from which I adapted the below code), but must not be identical since that was fixed in 1.55.0. Hopefully the same fix can be applied easily. </p> <pre class="wiki">$ cat polygonBug.cc #include &lt;vector&gt; #include &lt;boost/geometry.hpp&gt; #include &lt;boost/geometry/geometries/point_xy.hpp&gt; #include &lt;boost/geometry/geometries/polygon.hpp&gt; #include &lt;boost/geometry/geometries/register/point.hpp&gt; #include &lt;boost/geometry/geometries/register/ring.hpp&gt; #include &lt;boost/geometry/io/wkt/wkt.hpp&gt; #include &lt;boost/geometry/multi/geometries/multi_polygon.hpp&gt; typedef boost::geometry::model::d2::point_xy&lt;double&gt; pt; typedef boost::geometry::model::polygon&lt;pt&gt; polygon; typedef boost::geometry::model::multi_polygon&lt;polygon&gt; multi_polygon; int main() { polygon green, blue; multi_polygon output; boost::geometry::read_wkt("POLYGON((" " 14853.584999999999 20481.394 ," " 16484.061000000002 20466.799999999999 ," " 14853.584000000001 20481.392 ," " 14853.584999999999 20481.394))", green); boost::geometry::read_wkt("POLYGON((" " 16483.432000000001 20553.794000000002 ," " 16483.432000000001 20553.793000000001 ," " 16484.060000000001 20466.799999999999 ," " 16484.061000000002 20466.799999999999 ," " 14853.584999999999 20481.394 ," " 14854.127 20520.719000000001 ," " 16483.432000000001 20553.794000000002))", blue); boost::geometry::correct(green); boost::geometry::correct(blue); boost::geometry::intersection(green, blue, output); return 0; } $ clang++ -o polygonBug polygonBug.cc -I$BOOST_DIR/include $ ./polygonBug terminate called throwing an exceptionAbort trap: 6 </pre><p> Adding the following before using <code>boost::geometry::intersection</code> allows the call to succeed: </p> <pre class="wiki"> boost::geometry::simplify(green, green, 0.001); boost::geometry::simplify(blue, blue, 0.001); </pre><p> Relevant entries in the lldb backtrace: </p> <pre class="wiki"> frame #8: 0x0000000100002941 polygonBug`std::back_insert_iterator&lt;boost::geometry::model::multi_polygon&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, std::vector, std::allocator&gt; &gt; boost::geometry::detail::overlay::overlay&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, false, false, false, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, (boost::geometry::overlay_type)1&gt;::apply&lt;std::back_insert_iterator&lt;boost::geometry::model::multi_polygon&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, std::vector, std::allocator&gt; &gt;, boost::geometry::strategy_intersection&lt;boost::geometry::cartesian_tag, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, void&gt; &gt;(boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt; const&amp;, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt; const&amp;, std::back_insert_iterator&lt;boost::geometry::model::multi_polygon&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, std::vector, std::allocator&gt; &gt;, boost::geometry::strategy_intersection&lt;boost::geometry::cartesian_tag, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, void&gt; const&amp;) + 385 at overlay.hpp:230 frame #9: 0x000000010000279d polygonBug`bool boost::geometry::dispatch::intersection&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::polygon_tag, boost::geometry::polygon_tag, false&gt;::apply&lt;boost::geometry::model::multi_polygon&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, std::vector, std::allocator&gt;, boost::geometry::strategy_intersection&lt;boost::geometry::cartesian_tag, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, void&gt; &gt;(boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt; const&amp;, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt; const&amp;, boost::geometry::model::multi_polygon&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, std::vector, std::allocator&gt;&amp;, boost::geometry::strategy_intersection&lt;boost::geometry::cartesian_tag, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, void&gt; const&amp;) + 77 at intersection.hpp:103 frame #10: 0x00000001000026e3 polygonBug`bool boost::geometry::intersection&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, boost::geometry::model::multi_polygon&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, std::vector, std::allocator&gt; &gt;(boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt; const&amp;, boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt; const&amp;, boost::geometry::model::multi_polygon&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double, boost::geometry::cs::cartesian&gt;, true, true, std::vector, std::vector, std::allocator, std::allocator&gt;, std::vector, std::allocator&gt;&amp;) + 51 at intersection.hpp:198 </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9733 Trac 1.4.3 Barend Gehrels Sat, 22 Mar 2014 23:08:36 GMT status changed https://svn.boost.org/trac10/ticket/9733#comment:1 https://svn.boost.org/trac10/ticket/9733#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Barend Gehrels Sun, 23 Mar 2014 11:38:06 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9733#comment:2 https://svn.boost.org/trac10/ticket/9733#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> The second polygon (blue) is invalid. Boost.Geometry raises an exception for that. </p> <p> It is also reported as invalid by both SQL Server and PostGIS so we can conclude it is really invalid. </p> <p> "Self-intersection[16484.1 20466.8]" </p> <p> I close the ticket therefore as "invalid" too. </p> Ticket