#### /Src/Dependencies/Boost/libs/geometry/doc/src/examples/algorithms/simplify_insert_with_strategy.cpp

C++ | 75 lines | 23 code | 17 blank | 35 comment | 0 complexity | b147245f0e3d497682a6773e5b318315 MD5 | raw file
``` 1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// QuickBook Example
3
4// Copyright (c) 2011 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
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#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
19#include <boost/geometry/domains/gis/io/wkt/stream_wkt.hpp>
20
21
22
23int main()
24{
25    typedef boost::geometry::model::d2::point_xy<double> P;
26    typedef boost::geometry::model::linestring<P> L;
27
28    L line;
29    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);
30
31    typedef boost::geometry::strategy::distance::projected_point<P, P> DS;
32    typedef boost::geometry::strategy::simplify::douglas_peucker<P, DS> simplification;
33
34    L simplified;
35    boost::geometry::simplify_inserter(line, std::back_inserter(simplified), 0.5, simplification()); //std::ostream_iterator<P>(std::cout, "\n"), 0.5);//);
36    //std::cout << simplified[0];
37    //boost::geometry::simplify_inserter(line, std::ostream_iterator<P>(std::cout, "\n"), 0.5);//, simplification());
38
39    std::ostream_iterator<P> out(std::cout, "\n");
40    std::copy(simplified.begin(), simplified.end(), out);
41
42    std::cout
43        << "  original: " << boost::geometry::dsv(line) << std::endl
44        << "simplified: " << boost::geometry::dsv(simplified) << std::endl;
45
46    return 0;
47}
48
49//]
50
51
52//[simplify_inserter_output
53/*`
54Output:
55[pre
56simplify_inserter: 16
57simplify_inserter: 0.339837
58]
59*/
60//]
61/*
62OUTPUT
63POINT(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))
64simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
65*/
66/*
67OUTPUT
68POINT(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))
69simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
70*/
71/*
72OUTPUT
73POINT(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))
74simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
75*/
```