Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / geometry / example / 06_a_transformation_example.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //
11 // Transformation Example
12
13 #include <iostream>
14
15 #include <boost/geometry/geometry.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/polygon.hpp>
18 #include <boost/geometry/geometries/adapted/c_array.hpp>
19
20 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
21
22
23 int main()
24 {
25     using namespace boost::geometry;
26
27     typedef model::d2::point_xy<double> point_2d;
28     point_2d p(1, 1);
29     point_2d p2;
30
31     // Example: translate a point over (5,5)
32     strategy::transform::translate_transformer<double, 2, 2> translate(5, 5);
33
34     transform(p, p2, translate);
35     std::cout << "transformed point " << boost::geometry::dsv(p2) << std::endl;
36
37     // Transform a polygon
38     model::polygon<point_2d> poly, poly2;
39     const double coor[][2] = { {0, 0}, {0, 7}, {2, 2}, {2, 0}, {0, 0} };
40     // note that for this syntax you have to include the two
41     // include files above (c_array.hpp)
42     assign_points(poly, coor);
43     //read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", poly);
44     transform(poly, poly2, translate);
45
46     std::cout << "source      polygon " << boost::geometry::dsv(poly) << std::endl;
47     std::cout << "transformed polygon " << boost::geometry::dsv(poly2) << std::endl;
48
49     // Many more transformations are possible:
50     // - from Cartesian to Spherical coordinate systems and back
51     // - from Cartesian to Cartesian (mapping, affine transformations) and back (inverse)
52     // - Map Projections
53     // - from Degree to Radian and back in spherical_equatorial or geographic coordinate systems
54
55     return 0;
56 }