diff --git a/doc/src/examples/algorithms/assign_2d_point.cpp b/doc/src/examples/algorithms/assign_2d_point.cpp index 140f0f0c5..e01da8d7a 100644 --- a/doc/src/examples/algorithms/assign_2d_point.cpp +++ b/doc/src/examples/algorithms/assign_2d_point.cpp @@ -16,7 +16,7 @@ #include #include -#if defined(_MSC_VER) +#if defined(HAVE_TTMATH) # include #endif @@ -29,7 +29,7 @@ int main() boost::geometry::model::d2::point_xy p1; assign(p1, 1.2345, 2.3456); -#if defined(_MSC_VER) +#if defined(HAVE_TTMATH) boost::geometry::model::d2::point_xy > p2; assign(p2, "1.2345", "2.3456"); /*< It is possible to assign coordinates with other types than the coordinate type. For ttmath, you can e.g. conveniently use strings. The advantage is that it then has higher precision, because @@ -40,7 +40,7 @@ int main() std::cout << std::setprecision(20) << boost::geometry::dsv(p1) << std::endl -#if defined(_MSC_VER) +#if defined(HAVE_TTMATH) << boost::geometry::dsv(p2) << std::endl #endif ; diff --git a/doc/src/examples/algorithms/create_svg_overlay.hpp b/doc/src/examples/algorithms/create_svg_overlay.hpp index f44dd56e9..a8ed47bcf 100644 --- a/doc/src/examples/algorithms/create_svg_overlay.hpp +++ b/doc/src/examples/algorithms/create_svg_overlay.hpp @@ -13,11 +13,15 @@ #include #include -#include + +#if defined(HAVE_SVG) +# include +#endif template void create_svg(std::string const& filename, Geometry const& a, Geometry const& b, Range const& range) { +#if defined(HAVE_SVG) std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl; typedef typename boost::geometry::point_type::type point_type; @@ -38,6 +42,7 @@ void create_svg(std::string const& filename, Geometry const& a, Geometry const& mapper.text(boost::geometry::return_centroid(g), out.str(), "fill:rgb(0,0,0);font-family:Arial;font-size:10px"); } +#endif } // NOTE: convert manually from svg to png using Inkscape ctrl-shift-E diff --git a/doc/src/examples/algorithms/create_svg_two.hpp b/doc/src/examples/algorithms/create_svg_two.hpp index db7843a90..98be922c6 100644 --- a/doc/src/examples/algorithms/create_svg_two.hpp +++ b/doc/src/examples/algorithms/create_svg_two.hpp @@ -13,11 +13,15 @@ #include #include -#include + +#if defined(HAVE_SVG) +# include +#endif template void create_svg(std::string const& filename, Geometry1 const& a, Geometry2 const& b) { +#if defined(HAVE_SVG) std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl; typedef typename boost::geometry::point_type::type point_type; @@ -36,6 +40,7 @@ void create_svg(std::string const& filename, Geometry1 const& a, Geometry2 const { mapper.map(b, "opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-width:4;stroke-dasharray:1,7;stroke-linecap:round"); } +#endif } // NOTE: convert manually from svg to png using Inkscape ctrl-shift-E diff --git a/example/05_a_overlay_polygon_example.cpp b/example/05_a_overlay_polygon_example.cpp index 40d7b4633..9d74b8273 100644 --- a/example/05_a_overlay_polygon_example.cpp +++ b/example/05_a_overlay_polygon_example.cpp @@ -21,7 +21,9 @@ #include #include -#include +#if defined(HAVE_SVG) +# include +#endif int main(void) @@ -32,8 +34,10 @@ int main(void) typedef bg::model::polygon polygon_2d; +#if defined(HAVE_SVG) std::ofstream stream("05_a_intersection_polygon_example.svg"); bg::svg_mapper svg(stream, 500, 500); +#endif // Define a polygons and fill the outer rings. polygon_2d a; @@ -45,7 +49,6 @@ int main(void) } bg::correct(a); std::cout << "A: " << bg::dsv(a) << std::endl; - svg.add(a); polygon_2d b; { @@ -56,10 +59,13 @@ int main(void) } bg::correct(b); std::cout << "B: " << bg::dsv(b) << std::endl; +#if defined(HAVE_SVG) + svg.add(a); svg.add(b); svg.map(a, "opacity:0.6;fill:rgb(0,255,0);"); svg.map(b, "opacity:0.6;fill:rgb(0,0,255);"); +#endif // Calculate interesection(s) @@ -70,7 +76,9 @@ int main(void) BOOST_FOREACH(polygon_2d const& polygon, intersection) { std::cout << bg::dsv(polygon) << std::endl; +#if defined(HAVE_SVG) svg.map(polygon, "opacity:0.5;fill:none;stroke:rgb(255,0,0);stroke-width:6"); +#endif } return 0; diff --git a/example/05_b_overlay_linestring_polygon_example.cpp b/example/05_b_overlay_linestring_polygon_example.cpp index 93cc98861..16eff548e 100644 --- a/example/05_b_overlay_linestring_polygon_example.cpp +++ b/example/05_b_overlay_linestring_polygon_example.cpp @@ -21,7 +21,9 @@ #include #include -#include +#if defined(HAVE_SVG) +# include +#endif int main(void) @@ -43,6 +45,7 @@ int main(void) } bg::correct(p); +#if defined(HAVE_SVG) // Create SVG-mapper std::ofstream stream("05_b_overlay_linestring_polygon_example.svg"); bg::svg_mapper svg(stream, 500, 500); @@ -52,7 +55,7 @@ int main(void) // Map geometries svg.map(ls, "opacity:0.6;stroke:rgb(255,0,0);stroke-width:2;"); svg.map(p, "opacity:0.6;fill:rgb(0,0,255);"); - +#endif // Calculate intersection points (turn points) typedef bg::detail::overlay::turn_info turn_info; @@ -76,8 +79,10 @@ int main(void) } std::cout << action << " polygon at " << bg::dsv(turn.point) << std::endl; +#if defined(HAVE_SVG) svg.map(turn.point, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1"); svg.text(turn.point, action, "fill:rgb(0,0,0);font-family:Arial;font-size:10px"); +#endif } return 0; diff --git a/example/06_b_transformation_example.cpp b/example/06_b_transformation_example.cpp index f31c7fd13..0b6a0542b 100644 --- a/example/06_b_transformation_example.cpp +++ b/example/06_b_transformation_example.cpp @@ -19,9 +19,12 @@ #include #include #include -#include #include +#if defined(HAVE_SVG) +# include +#endif + #include #include #include @@ -84,8 +87,9 @@ struct svg_output void put(G const& g, std::string const& label) { std::string style_str(style.fill(opacity) + style.stroke(5, opacity)); - os << ::boost::geometry::svg(g, style_str) << std::endl; - +#if defined(HAVE_SVG) + os << boost::geometry::svg(g, style_str) << std::endl; +#endif if (!label.empty()) { typename point_type::type c; @@ -101,6 +105,7 @@ private: random_style style; }; + int main() { using namespace boost::geometry::strategy::transform; diff --git a/example/07_a_graph_route_example.cpp b/example/07_a_graph_route_example.cpp index a41575a25..4ea9c5ae8 100644 --- a/example/07_a_graph_route_example.cpp +++ b/example/07_a_graph_route_example.cpp @@ -30,10 +30,12 @@ // Yes, this example currently uses some extensions: // For output: - #include + #if defined(HAVE_SVG) + # include + #endif // For distance-calculations over the Earth: - #include + //#include @@ -260,10 +262,11 @@ inline void build_route(Graph const& graph, int main() { - // Define a point in the Geographic coordinate system + // Define a point in the Geographic coordinate system (currently Spherical) + // (geographic calculations are in an extension; for sample it makes no difference) typedef boost::geometry::model::point < - double, 2, boost::geometry::cs::geographic + double, 2, boost::geometry::cs::spherical > point_type; typedef boost::geometry::model::linestring line_type; @@ -302,8 +305,12 @@ int main() double const km = 1000.0; std::cout << "distances, all in KM" << std::endl << std::fixed << std::setprecision(0); + + // To calculate distance, declare and construct a strategy with average earth radius + boost::geometry::strategy::distance::haversine haversine(6372795.0); // Main functionality: calculate shortest routes from/to all cities + // For the first one, the complete route is stored as a linestring bool first = true; @@ -329,7 +336,7 @@ int main() if (! boost::equals(city1.get<1>(), city2.get<1>())) { double distance = costs[city2.get<2>()] / km; - double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>()) / km; + double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>(), haversine) / km; std::cout << std::setiosflags (std::ios_base::left) << std::setw(15) @@ -351,6 +358,7 @@ int main() } } +#if defined(HAVE_SVG) // Create the SVG std::ofstream stream("routes.svg"); boost::geometry::svg_mapper mapper(stream, 600, 600); @@ -378,6 +386,7 @@ int main() mapper.text(city.get<0>(), city.get<1>(), "fill:rgb(0,0,0);font-family:Arial;font-size:10px", 5, 5); } +#endif return 0; } diff --git a/example/07_b_graph_route_example.cpp b/example/07_b_graph_route_example.cpp index 7ab224433..64f4844c9 100644 --- a/example/07_b_graph_route_example.cpp +++ b/example/07_b_graph_route_example.cpp @@ -34,10 +34,12 @@ // Yes, this example currently uses some extensions: // For output: - #include + #if defined(HAVE_SVG) + # include + #endif // For distance-calculations over the Earth: - #include + //#include @@ -246,10 +248,11 @@ inline void build_route(Graph const& graph, int main() { - // Define a point in the Geographic coordinate system + // Define a point in the Geographic coordinate system (currently Spherical) + // (geographic calculations are in an extension; for sample it makes no difference) typedef boost::geometry::model::point < - double, 2, boost::geometry::cs::geographic + double, 2, boost::geometry::cs::spherical > point_type; typedef boost::geometry::model::linestring line_type; @@ -291,6 +294,9 @@ int main() std::cout << "distances, all in KM" << std::endl << std::fixed << std::setprecision(0); + // To calculate distance, declare and construct a strategy with average earth radius + boost::geometry::strategy::distance::haversine haversine(6372795.0); + // Main functionality: calculate shortest routes from/to all cities // For the first one, the complete route is stored as a linestring @@ -317,7 +323,7 @@ int main() if (! boost::equals(city1.get<1>(), city2.get<1>())) { double distance = costs[city2.get<2>()] / km; - double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>()) / km; + double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>(), haversine) / km; std::cout << std::setiosflags (std::ios_base::left) << std::setw(15) @@ -339,6 +345,7 @@ int main() } } +#if defined(HAVE_SVG) // Create the SVG std::ofstream stream("routes.svg"); boost::geometry::svg_mapper mapper(stream, 600, 600); @@ -366,6 +373,7 @@ int main() mapper.text(city.get<0>(), city.get<1>(), "fill:rgb(0,0,0);font-family:Arial;font-size:10px", 5, 5); } +#endif return 0; }