]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/doc/src/examples/algorithms/area.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
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)
11 //` Calculate the area of a polygon
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/polygon.hpp>
19 namespace bg
= boost::geometry
; /*< Convenient namespace alias >*/
23 // Calculate the area of a cartesian polygon
24 bg::model::polygon
<bg::model::d2::point_xy
<double> > poly
;
25 bg::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", poly
);
26 double area
= bg::area(poly
);
27 std::cout
<< "Area: " << area
<< std::endl
;
29 // Calculate the area of a spherical equatorial polygon
30 bg::model::polygon
<bg::model::point
<float, 2, bg::cs::spherical_equatorial
<bg::degree
> > > sph_poly
;
31 bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly
);
32 area
= bg::area(sph_poly
);
33 std::cout
<< "Area: " << area
<< std::endl
;