From a666d638eea3acfc9fbc50b241e4a96cf518ba9e Mon Sep 17 00:00:00 2001 From: Vissarion Fisikopoulos Date: Thu, 31 Oct 2024 16:19:05 +0200 Subject: [PATCH] ext: Modify and remove old examples. --- extensions/example/gis/Jamfile | 1 - extensions/example/gis/latlong/Jamfile | 4 +- .../example/gis/latlong/distance_example.cpp | 8 +- .../example/gis/latlong/point_ll_example.cpp | 4 +- extensions/example/gis/projections/Jamfile | 21 --- .../projections/p01_projection_example.cpp | 62 ------- .../projections/p02_projfactory_example.cpp | 64 -------- .../gis/projections/p03_projmap_example.cpp | 149 ----------------- .../example/gis/projections/p04_example.cpp | 127 -------------- .../example/gis/projections/p05_example.cpp | 155 ------------------ 10 files changed, 8 insertions(+), 587 deletions(-) delete mode 100644 extensions/example/gis/projections/Jamfile delete mode 100644 extensions/example/gis/projections/p01_projection_example.cpp delete mode 100644 extensions/example/gis/projections/p02_projfactory_example.cpp delete mode 100644 extensions/example/gis/projections/p03_projmap_example.cpp delete mode 100644 extensions/example/gis/projections/p04_example.cpp delete mode 100644 extensions/example/gis/projections/p05_example.cpp diff --git a/extensions/example/gis/Jamfile b/extensions/example/gis/Jamfile index 29f18278b..2e7f0da0c 100644 --- a/extensions/example/gis/Jamfile +++ b/extensions/example/gis/Jamfile @@ -16,4 +16,3 @@ project boost-geometry-extensions-gis-examples build-project latlong ; -build-project projections ; diff --git a/extensions/example/gis/latlong/Jamfile b/extensions/example/gis/latlong/Jamfile index 5b778831a..486a5daaf 100644 --- a/extensions/example/gis/latlong/Jamfile +++ b/extensions/example/gis/latlong/Jamfile @@ -13,5 +13,5 @@ project boost-geometry-example-extensions-gis-projections : # requirements ; -exe distance_example : distance_example.cpp ; -exe point_ll_example : point_ll_example.cpp ; +#exe distance_example : distance_example.cpp ; +#exe point_ll_example : point_ll_example.cpp ; diff --git a/extensions/example/gis/latlong/distance_example.cpp b/extensions/example/gis/latlong/distance_example.cpp index 265b2e86d..aa2c801b0 100644 --- a/extensions/example/gis/latlong/distance_example.cpp +++ b/extensions/example/gis/latlong/distance_example.cpp @@ -18,10 +18,10 @@ #include #include #include -#include -#include -#include -#include +//#include +//#include +//#include +//#include // BSG 28-10-2010 // TODO: clear up this test diff --git a/extensions/example/gis/latlong/point_ll_example.cpp b/extensions/example/gis/latlong/point_ll_example.cpp index dca4637b2..57afd74c3 100644 --- a/extensions/example/gis/latlong/point_ll_example.cpp +++ b/extensions/example/gis/latlong/point_ll_example.cpp @@ -60,7 +60,7 @@ int main() using namespace boost::geometry; typedef model::ll::point latlon_point; - + latlon_point paris; // Assign coordinates to the latlong point, using the methods lat and lon @@ -115,7 +115,7 @@ int main() // Other way round: have Amsterdam and go 430 km to the south (i.e. first calculate direction) double tc = get_course(amsterdam, paris); - std::cout << "Course: " << (tc * boost::geometry::math::r2d) << std::endl; + std::cout << "Course: " << (tc * boost::geometry::math::r2d()) << std::endl; latlon_point paris_calculated; point_at_distance(amsterdam, 430 * 1000.0, tc, average_earth_radius, paris_calculated); diff --git a/extensions/example/gis/projections/Jamfile b/extensions/example/gis/projections/Jamfile deleted file mode 100644 index 1b494ebe3..000000000 --- a/extensions/example/gis/projections/Jamfile +++ /dev/null @@ -1,21 +0,0 @@ -# Boost.Geometry (aka GGL, Generic Geometry Library) -# -# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. -# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. -# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. - -# 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) - - -project boost-geometry-example-extensions-gis-latlong - : requirements - /boost/foreach//boost_foreach - ; - -exe p01_projection_example : p01_projection_example.cpp ; -exe p02_projfactory_example : p02_projfactory_example.cpp ; -exe p03_projmap_example : p03_projmap_example.cpp ; -exe p04_example : p04_example.cpp ; -exe p05_example : p05_example.cpp ; diff --git a/extensions/example/gis/projections/p01_projection_example.cpp b/extensions/example/gis/projections/p01_projection_example.cpp deleted file mode 100644 index 1dbbfa0a4..000000000 --- a/extensions/example/gis/projections/p01_projection_example.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// 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; -} diff --git a/extensions/example/gis/projections/p02_projfactory_example.cpp b/extensions/example/gis/projections/p02_projfactory_example.cpp deleted file mode 100644 index 5e4ad1d3b..000000000 --- a/extensions/example/gis/projections/p02_projfactory_example.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// 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 2, using factory - -#include -#include - -#include -#include -#include - -#include - -int main() -{ - using namespace boost::geometry; - - // Initialize projection parameters. For construction using a factory the projection name is required. - projections::parameters par = projections::init("+proj=robin +ellps=WGS84 +units=m"); - - // Construct the specified projection, using specified point types - // Note that this is the only difference from p01_projection_example. It constructs a projection - // with virtual methods, which can be used polymorphically. Therefore it is a pointer. For - // convenience we use a boost shared pointer here. - typedef model::ll::point point_ll_deg; - typedef model::d2::point_xy point_xy; - projections::factory fac; - boost::shared_ptr > prj(fac.create_new(par)); - - // Define Amsterdam / Barcelona in decimal degrees / degrees/minutes - point_ll_deg amsterdam(longitude<>(5.9), latitude<>(52.4)); - point_ll_deg barcelona( - latitude<>(dms(41, 23)), - longitude<>(dms(2, 11)) - ); - - point_xy pa, pb; - - // Do the forward projection - 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; - - // Get the inverse - 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; -} diff --git a/extensions/example/gis/projections/p03_projmap_example.cpp b/extensions/example/gis/projections/p03_projmap_example.cpp deleted file mode 100644 index b906428e7..000000000 --- a/extensions/example/gis/projections/p03_projmap_example.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// 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 3, combined with shapelib and SVG - -#include - -#include -#include -#include -#include - -#include -#include -#include - -void read_wkt_and_project_and_write_svg(std::string const& wkt_filename, - std::string const& projection_parameters, - std::string const& svg_filename) -{ - using namespace boost::geometry; - - // Declare a vector containing the world countries - typedef model::ll::point point_ll_deg; - typedef model::polygon polygon_ll_deg; - std::vector ll_polygons; - - typedef model::d2::point_xy point_xy; - - // Read polygons from a Well-Known Text file using the ggl parser - std::ifstream cpp_file(wkt_filename.c_str()); - if (! cpp_file.is_open()) - { - throw std::string("File not found: ") + wkt_filename; - } - - while (! cpp_file.eof() ) - { - std::string line; - std::getline(cpp_file, line); - if (boost::starts_with(line, "MULTIPOLYGON")) - { - typedef boost::geometry::model::multi_polygon > mp_type; - mp_type mp; - boost::geometry::read_wkt(line, mp); - for (mp_type::const_iterator it = boost::begin(mp); - it != boost::end(mp); ++it) - { - ll_polygons.push_back(*it); - } - } - } - - // Our latlong polygon collection will be projected into this vector - // (Of course it is also possible to do this while reading and have one vector) - std::vector > xy_polygons; - - // Declare transformation strategy which contains a projection - projections::project_transformer - < - point_ll_deg, - point_xy - > projection(projection_parameters); - - // Project the polygons, and at the same time get the bounding box (in xy) - model::box bbox; - assign_inverse(bbox); - for (std::vector::const_iterator it = ll_polygons.begin(); - it != ll_polygons.end(); - ++it) - { - model::polygon xy_polygon; - - if (transform(*it, xy_polygon, projection)) - { - // Update bbox with box of this projected polygon - expand(bbox, return_envelope >(xy_polygon)); - - // Add projected polygon - xy_polygons.push_back(xy_polygon); - } - } - - // Create an SVG image - std::ofstream out(svg_filename.c_str()); - out - << "" << std::endl - << "" << std::endl - << "" << std::endl; - - // Setup the transformation to SVG - // (alternatively this could be skipped because SVG can transform itself, - // but this example shows it like this) - typedef boost::geometry::model::d2::point_xy svg_point; - boost::geometry::strategy::transform::map_transformer - < - double, 2, 2, - true, true - > svg_transformer(bbox, 800, 600); - - // Create the background - boost::geometry::model::box box; - boost::geometry::assign_values(box, 0, 0, 800, 600); - out << boost::geometry::svg(box, "fill:rgb(0,0,255)") << std::endl; - - for (std::vector >::const_iterator it = xy_polygons.begin(); - it != xy_polygons.end(); - ++it) - { - boost::geometry::model::polygon svg_polygon; - boost::geometry::transform(*it, svg_polygon, svg_transformer); - out << boost::geometry::svg(svg_polygon, - "fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:0.2") - << std::endl; - } - out << "" << std::endl; -} - -int main(int argc, char** argv) -{ - try - { - // Note, file location: trunk/libs/geometry/example/data - // update path below if necessary - read_wkt_and_project_and_write_svg( - "../../../../example/data/world.wkt", - "+proj=moll +ellps=clrk66", - "world.svg"); - } - catch(std::exception const& e) - { - std::cout << "Exception: " << e.what() << std::endl; - return 1; - } - catch(std::string const& s) - { - std::cout << "Exception: " << s << std::endl; - return 1; - } - - return 0; -} diff --git a/extensions/example/gis/projections/p04_example.cpp b/extensions/example/gis/projections/p04_example.cpp deleted file mode 100644 index d72684cd7..000000000 --- a/extensions/example/gis/projections/p04_example.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// Boost.Geometry (aka GGL, Generic Geometry Library) -// -// Copyright (c) 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) -// -// Projection example 4, reworked version of example 3 -// Now using svg mapper, multi polygons and specific transform strategy - -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -// Define a specific projection transformer -// (NOTE: this might become part of the library) -template -struct projection_transformer -{ - Projection const& m_prj; - - inline projection_transformer(Projection const& prj) - : m_prj(prj) - {} - - inline bool apply(typename Projection::geographic_point_type const& p1, - typename Projection::cartesian_point_type& p2) const - { - return m_prj.forward(p1, p2); - } -}; - -void read_wkt_and_project_and_map_svg(std::string const& wkt_filename, - std::string const& svg_filename) -{ - using namespace boost::geometry; - - typedef model::ll::point point_ll_deg; - typedef model::d2::point_xy point_xy; - - typedef model::multi_polygon > mp_ll; - typedef model::multi_polygon > mp_xy; - - typedef projections::robin_spheroid robin; - - std::vector countries_in_ll; - - // Read polygons from WKT - std::ifstream cpp_file(wkt_filename.c_str()); - if (! cpp_file.is_open()) - { - throw std::string("File not found: ") + wkt_filename; - } - - while (! cpp_file.eof() ) - { - std::string line; - std::getline(cpp_file, line); - if (boost::starts_with(line, "MULTIPOLYGON")) - { - countries_in_ll.resize(countries_in_ll.size() + 1); - boost::geometry::read_wkt(line, countries_in_ll.back()); - } - } - - robin prj(projections::init("+ellps=WGS84 +units=m")); - projection_transformer projection(prj); - - // Project the polygons, and at the same time get the bounding box (in xy) - std::vector countries_in_xy; - model::box bbox; - assign_inverse(bbox); - BOOST_FOREACH(mp_ll const& country_ll, countries_in_ll) - { - mp_xy country_xy; - if (transform(country_ll, country_xy, projection)) - { - expand(bbox, return_envelope >(country_xy)); - countries_in_xy.push_back(country_xy); - } - } - - // Create an SVG image - std::ofstream svg(svg_filename.c_str()); - boost::geometry::svg_mapper mapper(svg, 1000, 800); - mapper.add(bbox); - - BOOST_FOREACH(mp_xy const& country, countries_in_xy) - { - mapper.map(country, "fill-opacity:0.6;fill:rgb(153,204,0);stroke:rgb(0,128,0);stroke-width:0.2"); - } -} - -int main(int argc, char** argv) -{ - try - { - // Note, file location: trunk/libs/geometry/example/data - // update path below if necessary - read_wkt_and_project_and_map_svg( - "../../../../example/data/world.wkt", - "world4.svg"); - } - catch(std::exception const& e) - { - std::cout << "Exception: " << e.what() << std::endl; - return 1; - } - catch(std::string const& s) - { - std::cout << "Exception: " << s << std::endl; - return 1; - } - - return 0; -} diff --git a/extensions/example/gis/projections/p05_example.cpp b/extensions/example/gis/projections/p05_example.cpp deleted file mode 100644 index 499c6d5b2..000000000 --- a/extensions/example/gis/projections/p05_example.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// Boost.Geometry (aka GGL, Generic Geometry Library) -// -// Copyright (c) 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) -// -// Projection example 5 (reworked from 4), using small factory - -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include - -// Define a specific projection transformer -// (NOTE: this might become part of the library - copied from p04) -template -struct projection_transformer -{ - Projection const& m_prj; - - inline projection_transformer(Projection const& prj) - : m_prj(prj) - {} - - inline bool apply(typename Projection::geographic_point_type const& p1, - typename Projection::cartesian_point_type& p2) const - { - return m_prj.forward(p1, p2); - } -}; - -void p05_example(int projection_id, - std::string const& wkt_filename, - std::string const& svg_filename) -{ - using namespace boost::geometry; - using namespace boost::geometry::projections; - - typedef model::ll::point pll; - typedef model::d2::point_xy pxy; - - // Idea and headerfile "new_projection" submitted by Krzysztof Czainski: - // They are useful, when: - // - you have a small set of types of projections you'll use, - // - you know the type of projection during it's creation, and later - // you want to use it through an abstract base pointer, - // - you want to avoid the overhead of factory: generating code for - // creating a projection of every type you don't use, and selecting - // the type from a string. - - projection* prj = NULL; - - parameters pars = projections::init("+ellps=WGS84"); - switch(projection_id) - { - case 1 : prj = new_projection >(pars); break; - case 2 : prj = new_projection >(pars); break; - case 3 : prj = new_projection >(pars); break; - case 4 : prj = new_projection >(pars); break; - default : return; - } - - typedef model::multi_polygon > mp_ll; - typedef model::multi_polygon > mp_xy; - - std::vector countries_in_ll; - - // Read polygons from WKT - std::ifstream cpp_file(wkt_filename.c_str()); - if (! cpp_file.is_open()) - { - throw std::string("File not found: ") + wkt_filename; - } - - while (! cpp_file.eof() ) - { - std::string line; - std::getline(cpp_file, line); - if (boost::starts_with(line, "MULTIPOLYGON")) - { - countries_in_ll.resize(countries_in_ll.size() + 1); - boost::geometry::read_wkt(line, countries_in_ll.back()); - } - } - - projection_transformer > strategy(*prj); - - // Project the polygons, and at the same time get the bounding box (in xy) - std::vector countries_in_xy; - model::box bbox; - assign_inverse(bbox); - BOOST_FOREACH(mp_ll const& country_ll, countries_in_ll) - { - mp_xy country_xy; - if (transform(country_ll, country_xy, strategy)) - { - expand(bbox, return_envelope >(country_xy)); - countries_in_xy.push_back(country_xy); - } - } - - // Create an SVG image - std::ofstream svg(svg_filename.c_str()); - boost::geometry::svg_mapper mapper(svg, 1000, 800); - mapper.add(bbox); - - BOOST_FOREACH(mp_xy const& country, countries_in_xy) - { - mapper.map(country, "fill-opacity:0.6;fill:rgb(153,204,0);stroke:rgb(0,128,0);stroke-width:0.2"); - } - - delete prj; -} - -int main(int argc, char** argv) -{ - // Note, file location: trunk/libs/geometry/example/data - // update path below if necessary - std::string const data = "../../../../example/data/world.wkt"; - try - { - p05_example(1, data, "p05_world_1.svg"); - p05_example(2, data, "p05_world_2.svg"); - p05_example(3, data, "p05_world_3.svg"); - p05_example(4, data, "p05_world_4.svg"); - } - catch(std::exception const& e) - { - std::cerr << "Exception: " << e.what() << std::endl; - return 1; - } - catch(std::string const& s) - { - std::cerr << "Exception: " << s << std::endl; - return 1; - } - - return 0; -}