Ticket #9217: boost-geometry-wkt-close-ring.patch
File boost-geometry-wkt-close-ring.patch, 2.7 KB (added by , 9 years ago) |
---|
-
boost/geometry/io/wkt/write.hpp
119 119 { 120 120 template <typename Char, typename Traits> 121 121 static inline void apply(std::basic_ostream<Char, Traits>& os, 122 Range const& range )122 Range const& range, bool force_closed) 123 123 { 124 124 typedef typename boost::range_iterator<Range const>::type iterator_type; 125 125 126 typedef stream_coordinate 127 < 128 point_type, 0, dimension<point_type>::type::value 129 > stream_type; 130 126 131 bool first = true; 127 132 128 133 os << PrefixPolicy::apply(); … … 129 134 130 135 // TODO: check EMPTY here 131 136 132 for (iterator_type it= boost::begin(range);133 it != boost::end(range);134 137 iterator_type begin = boost::begin(range); 138 iterator_type end = boost::end(range); 139 for (iterator_type it = begin; it != end; ++it) 135 140 { 136 141 os << (first ? "" : ","); 137 stream_coordinate 138 < 139 point_type, 0, dimension<point_type>::type::value 140 >::apply(os, *it); 142 stream_type::apply(os, *it); 141 143 first = false; 142 144 } 143 145 146 // optionally, close range to ring by repeating the first point 147 if (force_closed && geometry::disjoint(*begin, *(end - 1))) 148 { 149 os << ","; 150 stream_type::apply(os, *begin); 151 } 152 144 153 os << SuffixPolicy::apply(); 145 154 } 146 155 156 template <typename Char, typename Traits> 157 static inline void apply(std::basic_ostream<Char, Traits>& os, 158 Range const& range) 159 { 160 apply(os, range, false); 161 } 162 147 163 private: 148 164 typedef typename boost::range_value<Range>::type point_type; 149 165 }; … … 170 186 Polygon const& poly) 171 187 { 172 188 typedef typename ring_type<Polygon const>::type ring; 189 bool const force_closed = true; 173 190 174 191 os << PrefixPolicy::apply(); 175 192 // TODO: check EMPTY here 176 193 os << "("; 177 wkt_sequence<ring>::apply(os, exterior_ring(poly) );194 wkt_sequence<ring>::apply(os, exterior_ring(poly), force_closed); 178 195 179 196 typename interior_return_type<Polygon const>::type rings 180 197 = interior_rings(poly); … … 181 198 for (BOOST_AUTO_TPL(it, boost::begin(rings)); it != boost::end(rings); ++it) 182 199 { 183 200 os << ","; 184 wkt_sequence<ring>::apply(os, *it );201 wkt_sequence<ring>::apply(os, *it, force_closed); 185 202 } 186 203 os << ")"; 187 204 }