// Boost.Geometry (aka GGL, Generic Geometry Library) // // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // 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) // // Projection example 1, direct #include #include #include #include #include #include int main() { using namespace boost::geometry; // Initialize projection parameters projections::parameters par = projections::init("+ellps=WGS84 +units=m"); // Construct a Robinson projection, using specified point types // (This delivers a projection without virtual methods. Note that in p02 example // the projection is created using a factory, which delivers a projection with virtual methods) typedef model::ll::point point_ll_deg; typedef model::d2::point_xy point_xy; projections::robin_spheroid prj(par); // Define Amsterdam / Barcelona in decimal degrees / degrees/minutes point_ll_deg amsterdam = parse("52.4N", "5.9E"); point_ll_deg barcelona = parse("41 23'N", "2 11'E"); point_xy pa, pb; // Now do the projection. "Forward" means from latlong to meters. // (Note that a map projection might fail. This is not 'exceptional'. // Therefore the forward function does not throw but returns false) if (prj.forward(amsterdam, pa) && prj.forward(barcelona, pb)) { std::cout << "Amsterdam: " << wkt(pa) << std::endl << "Barcelona: " << wkt(pb) << std::endl; std::cout << "Distance (unprojected):" << distance(amsterdam, barcelona) / 1000.0 << " km" << std::endl; std::cout << "Distance ( projected):" << distance(pa, pb) / 1000.0 << " km" << std::endl; // Do the inverse projection. "Inverse" means from meters to latlong // It also might fail or might not exist, not all projections // have their inverse implemented point_ll_deg a1; if (prj.inverse(pa, a1)) { std::cout << "Amsterdam (original): " << wkt(amsterdam) << std::endl << "Amsterdam (projected, and back):" << wkt(a1) << std::endl; std::cout << "Distance a-a': " << distance(amsterdam, a1) << " meter" << std::endl; } } return 0; }