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

http://hadesmem.googlecode.com/ · 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. // Copyright (c) 2011 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //[simplify_inserter
  8. //` Simplify a linestring using an output iterator
  9. #include <iostream>
  10. #include <boost/geometry.hpp>
  11. #include <boost/geometry/geometries/linestring.hpp>
  12. #include <boost/geometry/geometries/point_xy.hpp>
  13. #include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
  14. #include <boost/geometry/domains/gis/io/wkt/stream_wkt.hpp>
  15. int main()
  16. {
  17. typedef boost::geometry::model::d2::point_xy<double> P;
  18. typedef boost::geometry::model::linestring<P> L;
  19. L line;
  20. 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);
  21. typedef boost::geometry::strategy::distance::projected_point<P, P> DS;
  22. typedef boost::geometry::strategy::simplify::douglas_peucker<P, DS> simplification;
  23. L simplified;
  24. boost::geometry::simplify_inserter(line, std::back_inserter(simplified), 0.5, simplification()); //std::ostream_iterator<P>(std::cout, "\n"), 0.5);//);
  25. //std::cout << simplified[0];
  26. //boost::geometry::simplify_inserter(line, std::ostream_iterator<P>(std::cout, "\n"), 0.5);//, simplification());
  27. std::ostream_iterator<P> out(std::cout, "\n");
  28. std::copy(simplified.begin(), simplified.end(), out);
  29. std::cout
  30. << " original: " << boost::geometry::dsv(line) << std::endl
  31. << "simplified: " << boost::geometry::dsv(simplified) << std::endl;
  32. return 0;
  33. }
  34. //]
  35. //[simplify_inserter_output
  36. /*`
  37. Output:
  38. [pre
  39. simplify_inserter: 16
  40. simplify_inserter: 0.339837
  41. ]
  42. */
  43. //]
  44. /*
  45. OUTPUT
  46. 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))
  47. simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
  48. */
  49. /*
  50. OUTPUT
  51. 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))
  52. simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
  53. */
  54. /*
  55. OUTPUT
  56. 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))
  57. simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
  58. */