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

http://hadesmem.googlecode.com/ · C++ · 50 lines · 18 code · 12 blank · 20 comment · 0 complexity · abf77a01de72df3ad91c8ce9a7776571 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. //[area
  8. //` Calculate the area of a polygon
  9. #include <iostream>
  10. #include <boost/geometry.hpp>
  11. #include <boost/geometry/geometries/point_xy.hpp>
  12. #include <boost/geometry/geometries/polygon.hpp>
  13. #include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
  14. namespace bg = boost::geometry; /*< Convenient namespace alias >*/
  15. int main()
  16. {
  17. // Calculate the area of a cartesian polygon
  18. bg::model::polygon<bg::model::d2::point_xy<double> > poly;
  19. bg::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", poly);
  20. double area = bg::area(poly);
  21. std::cout << "Area: " << area << std::endl;
  22. // Calculate the area of a spherical equatorial polygon
  23. bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly;
  24. bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly);
  25. area = bg::area(sph_poly);
  26. std::cout << "Area: " << area << std::endl;
  27. return 0;
  28. }
  29. //]
  30. //[area_output
  31. /*`
  32. Output:
  33. [pre
  34. Area: 16
  35. Area: 0.339837
  36. ]
  37. */
  38. //]