mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-09 23:24:02 +00:00
Use haversine for linestring length as well, to fix route costs.
This commit is contained in:
parent
58b89fc252
commit
63077726a0
@ -31,12 +31,8 @@
|
||||
// For output:
|
||||
#include <boost/geometry/io/svg/svg_mapper.hpp>
|
||||
|
||||
// Yes, this example currently uses an extension:
|
||||
|
||||
// For distance-calculations over the Earth:
|
||||
//#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
|
||||
// Yes, this example currently uses some extensions:
|
||||
|
||||
|
||||
// Read an ASCII file containing WKT's, fill a vector of tuples
|
||||
// The tuples consist of at least <0> a geometry and <1> an identifying string
|
||||
@ -90,6 +86,9 @@ namespace boost
|
||||
BOOST_INSTALL_PROPERTY(edge, bg_property);
|
||||
}
|
||||
|
||||
// To calculate distance, declare and construct a strategy with average earth radius
|
||||
boost::geometry::strategy::distance::haversine<double> const haversine(6372795.0);
|
||||
|
||||
// Define properties for vertex
|
||||
template <typename Point>
|
||||
struct bg_vertex_property
|
||||
@ -99,8 +98,8 @@ struct bg_vertex_property
|
||||
boost::geometry::assign_zero(location);
|
||||
}
|
||||
bg_vertex_property(Point const& loc)
|
||||
: location(loc)
|
||||
{
|
||||
location = loc;
|
||||
}
|
||||
|
||||
Point location;
|
||||
@ -112,8 +111,8 @@ struct bg_edge_property
|
||||
{
|
||||
bg_edge_property(Linestring const& line)
|
||||
: m_line(line)
|
||||
, m_length(boost::geometry::length(line, haversine))
|
||||
{
|
||||
m_length = boost::geometry::length(line);
|
||||
}
|
||||
|
||||
inline operator double() const
|
||||
@ -305,9 +304,6 @@ 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<double> haversine(6372795.0);
|
||||
|
||||
// Main functionality: calculate shortest routes from/to all cities
|
||||
|
||||
|
||||
|
@ -34,8 +34,6 @@
|
||||
// For output:
|
||||
#include <boost/geometry/io/svg/svg_mapper.hpp>
|
||||
|
||||
// Yes, this example currently uses an extension:
|
||||
|
||||
// For distance-calculations over the Earth:
|
||||
//#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
|
||||
|
||||
@ -82,7 +80,8 @@ void read_wkt(std::string const& filename, std::vector<Tuple>& tuples, Box& box)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// To calculate distance, declare and construct a strategy with average earth radius
|
||||
boost::geometry::strategy::distance::haversine<double> const haversine(6372795.0);
|
||||
|
||||
// Define properties for vertex
|
||||
template <typename Point>
|
||||
@ -93,8 +92,8 @@ struct bg_vertex_property
|
||||
boost::geometry::assign_zero(location);
|
||||
}
|
||||
bg_vertex_property(Point const& loc)
|
||||
: location(loc)
|
||||
{
|
||||
location = loc;
|
||||
}
|
||||
|
||||
Point location;
|
||||
@ -106,8 +105,8 @@ struct bg_edge_property
|
||||
{
|
||||
bg_edge_property(Linestring const& line)
|
||||
: m_line(line)
|
||||
, length(boost::geometry::length(line, haversine))
|
||||
{
|
||||
length = boost::geometry::length(line);
|
||||
}
|
||||
|
||||
inline Linestring const& line() const
|
||||
@ -292,9 +291,6 @@ 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<double> haversine(6372795.0);
|
||||
|
||||
// Main functionality: calculate shortest routes from/to all cities
|
||||
|
||||
// For the first one, the complete route is stored as a linestring
|
||||
|
Loading…
x
Reference in New Issue
Block a user