summaryrefslogtreecommitdiff
path: root/libs/geometry/doc/src/examples/algorithms/area_with_strategy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/geometry/doc/src/examples/algorithms/area_with_strategy.cpp')
-rw-r--r--libs/geometry/doc/src/examples/algorithms/area_with_strategy.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/libs/geometry/doc/src/examples/algorithms/area_with_strategy.cpp b/libs/geometry/doc/src/examples/algorithms/area_with_strategy.cpp
new file mode 100644
index 000000000..c0a7bfc18
--- /dev/null
+++ b/libs/geometry/doc/src/examples/algorithms/area_with_strategy.cpp
@@ -0,0 +1,50 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+// QuickBook Example
+
+// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
+
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+//[area_with_strategy
+//` Calculate the area of a polygon
+
+#include <iostream>
+
+#include <boost/geometry.hpp>
+#include <boost/geometry/geometries/point_xy.hpp>
+#include <boost/geometry/geometries/polygon.hpp>
+#include <boost/geometry/io/wkt/wkt.hpp>
+
+namespace bg = boost::geometry; /*< Convenient namespace alias >*/
+
+int main()
+{
+ // Calculate the area of a cartesian polygon
+ bg::model::polygon<bg::model::d2::point_xy<double> > poly;
+ bg::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", poly);
+ double area = bg::area(poly);
+ std::cout << "Area: " << area << std::endl;
+
+ // Calculate the area of a spherical polygon (for latitude: 0 at equator)
+ bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly;
+ bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly);
+ area = bg::area(sph_poly);
+ std::cout << "Area: " << area << std::endl;
+
+ return 0;
+}
+
+//]
+
+
+//[area_with_strategy_output
+/*`
+Output:
+[pre
+Area: 16
+Area: 0.339837
+]
+*/
+//]