3030// Yes, this example currently uses some extensions:
3131
3232 // For output:
33- #include < boost/geometry/extensions/io/svg/svg_mapper.hpp>
33+ #if defined(HAVE_SVG)
34+ # include < boost/geometry/extensions/io/svg/svg_mapper.hpp>
35+ #endif
3436
3537 // For distance-calculations over the Earth:
36- #include < boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
38+ // #include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
3739
3840
3941
@@ -260,10 +262,11 @@ inline void build_route(Graph const& graph,
260262
261263int main ()
262264{
263- // Define a point in the Geographic coordinate system
265+ // Define a point in the Geographic coordinate system (currently Spherical)
266+ // (geographic calculations are in an extension; for sample it makes no difference)
264267 typedef boost::geometry::model::point
265268 <
266- double , 2 , boost::geometry::cs::geographic <boost::geometry::degree>
269+ double , 2 , boost::geometry::cs::spherical <boost::geometry::degree>
267270 > point_type;
268271
269272 typedef boost::geometry::model::linestring<point_type> line_type;
@@ -302,8 +305,12 @@ int main()
302305 double const km = 1000.0 ;
303306 std::cout << " distances, all in KM" << std::endl
304307 << std::fixed << std::setprecision (0 );
308+
309+ // To calculate distance, declare and construct a strategy with average earth radius
310+ boost::geometry::strategy::distance::haversine<point_type> haversine (6372795.0 );
305311
306312 // Main functionality: calculate shortest routes from/to all cities
313+
307314
308315 // For the first one, the complete route is stored as a linestring
309316 bool first = true ;
@@ -329,7 +336,7 @@ int main()
329336 if (! boost::equals (city1.get <1 >(), city2.get <1 >()))
330337 {
331338 double distance = costs[city2.get <2 >()] / km;
332- double acof = boost::geometry::distance (city1.get <0 >(), city2.get <0 >()) / km;
339+ double acof = boost::geometry::distance (city1.get <0 >(), city2.get <0 >(), haversine ) / km;
333340
334341 std::cout
335342 << std::setiosflags (std::ios_base::left) << std::setw (15 )
@@ -351,6 +358,7 @@ int main()
351358 }
352359 }
353360
361+ #if defined(HAVE_SVG)
354362 // Create the SVG
355363 std::ofstream stream (" routes.svg" );
356364 boost::geometry::svg_mapper<point_type> mapper (stream, 600 , 600 );
@@ -378,6 +386,7 @@ int main()
378386 mapper.text (city.get <0 >(), city.get <1 >(),
379387 " fill:rgb(0,0,0);font-family:Arial;font-size:10px" , 5 , 5 );
380388 }
389+ #endif
381390
382391 return 0 ;
383392}
0 commit comments