1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
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)
11 // Transformation Example
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>
20 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
25 using namespace boost::geometry;
27 typedef model::d2::point_xy<double> point_2d;
31 // Example: translate a point over (5,5)
32 strategy::transform::translate_transformer<double, 2, 2> translate(5, 5);
34 transform(p, p2, translate);
35 std::cout << "transformed point " << boost::geometry::dsv(p2) << std::endl;
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);
46 std::cout << "source polygon " << boost::geometry::dsv(poly) << std::endl;
47 std::cout << "transformed polygon " << boost::geometry::dsv(poly2) << std::endl;
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)
53 // - from Degree to Radian and back in spherical_equatorial or geographic coordinate systems