diff --git a/include/boost/geometry/algorithms/dissolve.hpp b/include/boost/geometry/algorithms/dissolve.hpp index ff5753a9b..b63a28be9 100644 --- a/include/boost/geometry/algorithms/dissolve.hpp +++ b/include/boost/geometry/algorithms/dissolve.hpp @@ -145,6 +145,10 @@ struct dissolve (e.g. vector of "intersection/turn point"'s) \param geometry first geometry \param output container which will contain dissolved geometry + \note Currently dissolve with a (multi)linestring does NOT remove internal + overlap, it only tries to connect multiple line end-points. + TODO: we should change this behaviour and add a separate "connect" + algorithm, and let dissolve work like polygon. */ template < diff --git a/include/boost/geometry/multi/algorithms/dissolve.hpp b/include/boost/geometry/multi/algorithms/dissolve.hpp index ffa10fd2e..a9d8a36a5 100644 --- a/include/boost/geometry/multi/algorithms/dissolve.hpp +++ b/include/boost/geometry/multi/algorithms/dissolve.hpp @@ -108,19 +108,27 @@ struct dissolve_multi_linestring } static inline map_iterator_type find_start(map_type const& map, - std::map& included) + std::map& included, int expected_count = 1) { for (map_iterator_type it = map.begin(); it != map.end(); ++it) { int count = map.count(it->first); - if (count == 1 && ! included[it->second.index]) + if (count == expected_count && ! included[it->second.index]) { included[it->second.index] = true; return it; } } + + // Not found with one point, try one with two points + // to find rings + if (expected_count == 1) + { + return find_start(map, included, 2); + } + return map.end(); } diff --git a/test/multi/algorithms/multi_dissolve.cpp b/test/multi/algorithms/multi_dissolve.cpp index 9a886e602..4dc427fe9 100644 --- a/test/multi/algorithms/multi_dissolve.cpp +++ b/test/multi/algorithms/multi_dissolve.cpp @@ -78,6 +78,12 @@ void test_all() test_one("ls_simplex_two", "MULTILINESTRING((0 0,1 1),(1 1,2 2),(3 3,4 4),(4 4,5 5))", 0, 6, 4 * std::sqrt(2.0)); + + // Linestrings forming a ring + test_one("ls_simplex_ring", + "MULTILINESTRING((0 0,0 1),(1 1,1 0),(0 1,1 1),(1 0,0 0))", + 0, 5, 4.0); + }