Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / geometry / doc / src / examples / algorithms / simplify_insert_with_strategy.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // QuickBook Example
3
4 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 //[simplify_inserter
11 //` Simplify a linestring using an output iterator
12
13 #include <iostream>
14
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/linestring.hpp>
17 #include <boost/geometry/geometries/point_xy.hpp>
18
19 int main()
20 {
21     typedef boost::geometry::model::d2::point_xy<double> P;
22     typedef boost::geometry::model::linestring<P> L;
23
24     L line;
25     boost::geometry::read_wkt("linestring(1.1 1.1, 2.5 2.1, 3.1 3.1, 4.9 1.1, 3.1 1.9)", line);
26
27     typedef boost::geometry::strategy::distance::projected_point<P, P> DS;
28     typedef boost::geometry::strategy::simplify::douglas_peucker<P, DS> simplification;
29
30     L simplified;
31     boost::geometry::simplify_inserter(line, std::back_inserter(simplified), 0.5, simplification()); //std::ostream_iterator<P>(std::cout, "\n"), 0.5);//);
32     //std::cout << simplified[0];
33     //boost::geometry::simplify_inserter(line, std::ostream_iterator<P>(std::cout, "\n"), 0.5);//, simplification());
34
35     std::ostream_iterator<P> out(std::cout, "\n");
36     std::copy(simplified.begin(), simplified.end(), out);
37
38     std::cout
39         << "  original: " << boost::geometry::dsv(line) << std::endl
40         << "simplified: " << boost::geometry::dsv(simplified) << std::endl;
41
42     return 0;
43 }
44
45 //]
46
47
48 //[simplify_inserter_output
49 /*`
50 Output:
51 [pre
52 simplify_inserter: 16
53 simplify_inserter: 0.339837
54 ]
55 */
56 //]
57 /*
58 OUTPUT
59 POINT(1.1 1.1)  original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
60 simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
61 */
62 /*
63 OUTPUT
64 POINT(1.1 1.1)  original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
65 simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
66 */
67 /*
68 OUTPUT
69 POINT(1.1 1.1)  original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
70 simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
71 */