• 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 // This file was modified by Oracle on 2018.
7 // Modifications copyright (c) 2018 Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9 
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13 
14 //[area_with_strategy
15 //` Calculate the area of a polygon
16 
17 #include <iostream>
18 
19 #include <boost/geometry.hpp>
20 #include <boost/geometry/geometries/point_xy.hpp>
21 #include <boost/geometry/geometries/polygon.hpp>
22 
23 namespace bg = boost::geometry; /*< Convenient namespace alias >*/
24 
main()25 int main()
26 {
27     // Create spherical polygon
28     bg::model::polygon<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly;
29     bg::read_wkt("POLYGON((0 0,0 1,1 0,0 0))", sph_poly);
30 
31     // Create spherical strategy with mean Earth radius in meters
32     bg::strategy::area::spherical<> sph_strategy(6371008.8);
33 
34     // Calculate the area of a spherical polygon
35     double area = bg::area(sph_poly, sph_strategy);
36     std::cout << "Area: " << area << std::endl;
37 
38     // Create geographic polygon
39     bg::model::polygon<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > > geo_poly;
40     bg::read_wkt("POLYGON((0 0,0 1,1 0,0 0))", geo_poly);
41 
42     // Create geographic strategy with WGS84 spheroid
43     bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
44     bg::strategy::area::geographic<> geo_strategy(spheroid);
45 
46     // Calculate the area of a geographic polygon
47     area = bg::area(geo_poly, geo_strategy);
48     std::cout << "Area: " << area << std::endl;
49 
50     return 0;
51 }
52 
53 //]
54 
55 
56 //[area_with_strategy_output
57 /*`
58 Output:
59 [pre
60 Area: 6.18249e+09
61 Area: 6.15479e+09
62 ]
63 */
64 //]
65