06_a_transformation_example.cpp

This sample demonstrates the usage of transformations in the Generic Geometry Library. Behind the screens this is done using with the uBLAS matrix/vector library.

    //Boost.Geometry(akaGGL,GenericGeometryLibrary)

    //Copyright(c)2007-2012BarendGehrels,Amsterdam,theNetherlands.
    //Copyright(c)2008-2012BrunoLalande,Paris,France.
    //Copyright(c)2009-2012MateuszLoskot,London,UK.

    //Use,modificationanddistributionissubjecttotheBoostSoftwareLicense,
    //Version1.0.(SeeaccompanyingfileLICENSE_1_0.txtorcopyat
    //http://www.boost.org/LICENSE_1_0.txt)
    //
    //TransformationExample

    #include<iostream>

    #include<boost/geometry/geometry.hpp>
    #include<boost/geometry/geometries/point_xy.hpp>
    #include<boost/geometry/geometries/polygon.hpp>
    #include<boost/geometry/geometries/adapted/c_array.hpp>

    BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)

    intmain()
    {
    usingnamespaceboost::geometry;

    typedefmodel::d2::point_xy<double>point_2d;
    point_2dp(1,1);
    point_2dp2;

    //Example:translateapointover(5,5)
    strategy::transform::translate_transformer<double, 2, 2>translate(5,5);

    transform(p,p2,translate);
    std::cout<<"transformedpoint"<<boost::geometry::dsv(p2)<<std::endl;

    //Transformapolygon
    model::polygon<point_2d>poly,poly2;
    constdoublecoor[][2]={{0,0},{0,7},{2,2},{2,0},{0,0}};
    //notethatforthissyntaxyouhavetoincludethetwo
    //includefilesabove(c_array.hpp)
    assign_points(poly,coor);
    //read_wkt("POLYGON((00,07,42,20,00))",poly);
    transform(poly,poly2,translate);

    std::cout<<"sourcepolygon"<<boost::geometry::dsv(poly)<<std::endl;
    std::cout<<"transformedpolygon"<<boost::geometry::dsv(poly2)<<std::endl;

    //Manymoretransformationsarepossible:
    //-fromCartesiantoSphericalcoordinatesystemsandback
    //-fromCartesiantoCartesian(mapping,affinetransformations)andback(inverse)
    //-MapProjections
    //-fromDegreetoRadianandbackinspherical_equatorialorgeographiccoordinatesystems

    return0;
    }