comparison DEPENDENCIES/generic/include/boost/geometry/io/wkt/write.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
1 // Boost.Geometry (aka GGL, Generic Geometry Library) 1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. 3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. 4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. 5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6 // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
6 7
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library 8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. 9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
9 10
10 // Use, modification and distribution is subject to the Boost Software License, 11 // Use, modification and distribution is subject to the Boost Software License,
17 #include <ostream> 18 #include <ostream>
18 #include <string> 19 #include <string>
19 20
20 #include <boost/array.hpp> 21 #include <boost/array.hpp>
21 #include <boost/range.hpp> 22 #include <boost/range.hpp>
22 #include <boost/typeof/typeof.hpp> 23
23 24 #include <boost/variant/apply_visitor.hpp>
25 #include <boost/variant/static_visitor.hpp>
26 #include <boost/variant/variant_fwd.hpp>
27
28 #include <boost/geometry/algorithms/detail/interior_iterator.hpp>
24 #include <boost/geometry/algorithms/assign.hpp> 29 #include <boost/geometry/algorithms/assign.hpp>
25 #include <boost/geometry/algorithms/convert.hpp> 30 #include <boost/geometry/algorithms/convert.hpp>
31 #include <boost/geometry/algorithms/disjoint.hpp>
26 #include <boost/geometry/algorithms/not_implemented.hpp> 32 #include <boost/geometry/algorithms/not_implemented.hpp>
27 #include <boost/geometry/core/exterior_ring.hpp> 33 #include <boost/geometry/core/exterior_ring.hpp>
28 #include <boost/geometry/core/interior_rings.hpp> 34 #include <boost/geometry/core/interior_rings.hpp>
29 #include <boost/geometry/core/ring_type.hpp> 35 #include <boost/geometry/core/ring_type.hpp>
36 #include <boost/geometry/core/tags.hpp>
30 37
31 #include <boost/geometry/geometries/concepts/check.hpp> 38 #include <boost/geometry/geometries/concepts/check.hpp>
32 #include <boost/geometry/geometries/ring.hpp> 39 #include <boost/geometry/geometries/ring.hpp>
33 40
34 #include <boost/geometry/io/wkt/detail/prefix.hpp> 41 #include <boost/geometry/io/wkt/detail/prefix.hpp>
35 42
36 #include <boost/variant/apply_visitor.hpp>
37 #include <boost/variant/static_visitor.hpp>
38 #include <boost/variant/variant_fwd.hpp>
39 43
40 namespace boost { namespace geometry 44 namespace boost { namespace geometry
41 { 45 {
42 46
43 // Silence warning C4512: 'boost::geometry::wkt_manipulator<Geometry>' : assignment operator could not be generated 47 // Silence warning C4512: 'boost::geometry::wkt_manipulator<Geometry>' : assignment operator could not be generated
117 template <typename Range, typename PrefixPolicy, typename SuffixPolicy> 121 template <typename Range, typename PrefixPolicy, typename SuffixPolicy>
118 struct wkt_range 122 struct wkt_range
119 { 123 {
120 template <typename Char, typename Traits> 124 template <typename Char, typename Traits>
121 static inline void apply(std::basic_ostream<Char, Traits>& os, 125 static inline void apply(std::basic_ostream<Char, Traits>& os,
122 Range const& range) 126 Range const& range, bool force_closed)
123 { 127 {
124 typedef typename boost::range_iterator<Range const>::type iterator_type; 128 typedef typename boost::range_iterator<Range const>::type iterator_type;
125 129
130 typedef stream_coordinate
131 <
132 point_type, 0, dimension<point_type>::type::value
133 > stream_type;
134
126 bool first = true; 135 bool first = true;
127 136
128 os << PrefixPolicy::apply(); 137 os << PrefixPolicy::apply();
129 138
130 // TODO: check EMPTY here 139 // TODO: check EMPTY here
131 140
132 for (iterator_type it = boost::begin(range); 141 iterator_type begin = boost::begin(range);
133 it != boost::end(range); 142 iterator_type end = boost::end(range);
134 ++it) 143 for (iterator_type it = begin; it != end; ++it)
135 { 144 {
136 os << (first ? "" : ","); 145 os << (first ? "" : ",");
137 stream_coordinate 146 stream_type::apply(os, *it);
138 <
139 point_type, 0, dimension<point_type>::type::value
140 >::apply(os, *it);
141 first = false; 147 first = false;
142 } 148 }
143 149
150 // optionally, close range to ring by repeating the first point
151 if (force_closed
152 && boost::size(range) > 1
153 && geometry::disjoint(*begin, *(end - 1)))
154 {
155 os << ",";
156 stream_type::apply(os, *begin);
157 }
158
144 os << SuffixPolicy::apply(); 159 os << SuffixPolicy::apply();
160 }
161
162 template <typename Char, typename Traits>
163 static inline void apply(std::basic_ostream<Char, Traits>& os,
164 Range const& range)
165 {
166 apply(os, range, false);
145 } 167 }
146 168
147 private: 169 private:
148 typedef typename boost::range_value<Range>::type point_type; 170 typedef typename boost::range_value<Range>::type point_type;
149 }; 171 };
168 template <typename Char, typename Traits> 190 template <typename Char, typename Traits>
169 static inline void apply(std::basic_ostream<Char, Traits>& os, 191 static inline void apply(std::basic_ostream<Char, Traits>& os,
170 Polygon const& poly) 192 Polygon const& poly)
171 { 193 {
172 typedef typename ring_type<Polygon const>::type ring; 194 typedef typename ring_type<Polygon const>::type ring;
195 bool const force_closed = true;
173 196
174 os << PrefixPolicy::apply(); 197 os << PrefixPolicy::apply();
175 // TODO: check EMPTY here 198 // TODO: check EMPTY here
176 os << "("; 199 os << "(";
177 wkt_sequence<ring>::apply(os, exterior_ring(poly)); 200 wkt_sequence<ring>::apply(os, exterior_ring(poly), force_closed);
178 201
179 typename interior_return_type<Polygon const>::type rings 202 typename interior_return_type<Polygon const>::type
180 = interior_rings(poly); 203 rings = interior_rings(poly);
181 for (BOOST_AUTO_TPL(it, boost::begin(rings)); it != boost::end(rings); ++it) 204 for (typename detail::interior_iterator<Polygon const>::type
205 it = boost::begin(rings); it != boost::end(rings); ++it)
182 { 206 {
183 os << ","; 207 os << ",";
184 wkt_sequence<ring>::apply(os, *it); 208 wkt_sequence<ring>::apply(os, *it, force_closed);
185 } 209 }
210 os << ")";
211 }
212 };
213
214 template <typename Multi, typename StreamPolicy, typename PrefixPolicy>
215 struct wkt_multi
216 {
217 template <typename Char, typename Traits>
218 static inline void apply(std::basic_ostream<Char, Traits>& os,
219 Multi const& geometry)
220 {
221 os << PrefixPolicy::apply();
222 // TODO: check EMPTY here
223 os << "(";
224
225 for (typename boost::range_iterator<Multi const>::type
226 it = boost::begin(geometry);
227 it != boost::end(geometry);
228 ++it)
229 {
230 if (it != boost::begin(geometry))
231 {
232 os << ",";
233 }
234 StreamPolicy::apply(os, *it);
235 }
236
186 os << ")"; 237 os << ")";
187 } 238 }
188 }; 239 };
189 240
190 template <typename Box> 241 template <typename Box>
311 struct wkt<Polygon, polygon_tag> 362 struct wkt<Polygon, polygon_tag>
312 : detail::wkt::wkt_poly 363 : detail::wkt::wkt_poly
313 < 364 <
314 Polygon, 365 Polygon,
315 detail::wkt::prefix_polygon 366 detail::wkt::prefix_polygon
367 >
368 {};
369
370 template <typename Multi>
371 struct wkt<Multi, multi_point_tag>
372 : detail::wkt::wkt_multi
373 <
374 Multi,
375 detail::wkt::wkt_point
376 <
377 typename boost::range_value<Multi>::type,
378 detail::wkt::prefix_null
379 >,
380 detail::wkt::prefix_multipoint
381 >
382 {};
383
384 template <typename Multi>
385 struct wkt<Multi, multi_linestring_tag>
386 : detail::wkt::wkt_multi
387 <
388 Multi,
389 detail::wkt::wkt_sequence
390 <
391 typename boost::range_value<Multi>::type
392 >,
393 detail::wkt::prefix_multilinestring
394 >
395 {};
396
397 template <typename Multi>
398 struct wkt<Multi, multi_polygon_tag>
399 : detail::wkt::wkt_multi
400 <
401 Multi,
402 detail::wkt::wkt_poly
403 <
404 typename boost::range_value<Multi>::type,
405 detail::wkt::prefix_null
406 >,
407 detail::wkt::prefix_multipolygon
316 > 408 >
317 {}; 409 {};
318 410
319 411
320 template <typename Geometry> 412 template <typename Geometry>
394 Geometry const& m_geometry; 486 Geometry const& m_geometry;
395 }; 487 };
396 488
397 /*! 489 /*!
398 \brief Main WKT-streaming function 490 \brief Main WKT-streaming function
491 \tparam Geometry \tparam_geometry
492 \param geometry \param_geometry
399 \ingroup wkt 493 \ingroup wkt
400 \par Example: 494 \qbk{[include reference/io/wkt.qbk]}
401 Small example showing how to use the wkt helper function
402 \dontinclude doxygen_1.cpp
403 \skip example_as_wkt_vector
404 \line {
405 \until }
406 */ 495 */
407 template <typename Geometry> 496 template <typename Geometry>
408 inline wkt_manipulator<Geometry> wkt(Geometry const& geometry) 497 inline wkt_manipulator<Geometry> wkt(Geometry const& geometry)
409 { 498 {
410 concept::check<Geometry const>(); 499 concept::check<Geometry const>();