• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
11 //` Example showing how to simplify a linestring
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 /*< For this example we use Boost.Assign to add points >*/
20 #include <boost/assign.hpp>
21 
22 using namespace boost::assign;
23 
24 
main()25 int main()
26 {
27     typedef boost::geometry::model::d2::point_xy<double> xy;
28 
29     boost::geometry::model::linestring<xy> line;
30     line += xy(1.1, 1.1), xy(2.5, 2.1), xy(3.1, 3.1), xy(4.9, 1.1), xy(3.1, 1.9); /*< With Boost.Assign >*/
31 
32     // Simplify it, using distance of 0.5 units
33     boost::geometry::model::linestring<xy> simplified;
34     boost::geometry::simplify(line, simplified, 0.5);
35     std::cout
36         << "  original: " << boost::geometry::dsv(line) << std::endl
37         << "simplified: " << boost::geometry::dsv(simplified) << std::endl;
38 
39 
40     return 0;
41 }
42 
43 //]
44 
45 
46 //[simplify_output
47 /*`
48 Output:
49 [pre
50   original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
51 simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
52 ]
53 */
54 //]
55