Index: boost/geometry/io/wkt/write.hpp =================================================================== --- boost/geometry/io/wkt/write.hpp (revision 85516) +++ boost/geometry/io/wkt/write.hpp (working copy) @@ -119,10 +119,15 @@ { template static inline void apply(std::basic_ostream& os, - Range const& range) + Range const& range, bool force_closed) { typedef typename boost::range_iterator::type iterator_type; + typedef stream_coordinate + < + point_type, 0, dimension::type::value + > stream_type; + bool first = true; os << PrefixPolicy::apply(); @@ -129,21 +134,32 @@ // TODO: check EMPTY here - for (iterator_type it = boost::begin(range); - it != boost::end(range); - ++it) + iterator_type begin = boost::begin(range); + iterator_type end = boost::end(range); + for (iterator_type it = begin; it != end; ++it) { os << (first ? "" : ","); - stream_coordinate - < - point_type, 0, dimension::type::value - >::apply(os, *it); + stream_type::apply(os, *it); first = false; } + // optionally, close range to ring by repeating the first point + if (force_closed && geometry::disjoint(*begin, *(end - 1))) + { + os << ","; + stream_type::apply(os, *begin); + } + os << SuffixPolicy::apply(); } + template + static inline void apply(std::basic_ostream& os, + Range const& range) + { + apply(os, range, false); + } + private: typedef typename boost::range_value::type point_type; }; @@ -170,11 +186,12 @@ Polygon const& poly) { typedef typename ring_type::type ring; + bool const force_closed = true; os << PrefixPolicy::apply(); // TODO: check EMPTY here os << "("; - wkt_sequence::apply(os, exterior_ring(poly)); + wkt_sequence::apply(os, exterior_ring(poly), force_closed); typename interior_return_type::type rings = interior_rings(poly); @@ -181,7 +198,7 @@ for (BOOST_AUTO_TPL(it, boost::begin(rings)); it != boost::end(rings); ++it) { os << ","; - wkt_sequence::apply(os, *it); + wkt_sequence::apply(os, *it, force_closed); } os << ")"; }