Boost
C++ Libraries
...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
This is an older version of Boost and was released in 2024. The current version is 1.90.0.
Calculate the discrete Frechet distance between two geometries using the specified strategy.
The free function discrete_frechet_distance calculates
the discrete Frechet distance between two geometries.
template<typename Geometry1, typename Geometry2, typename Strategy> auto discrete_frechet_distance(Geometry1 const & geometry1, Geometry2 const & geometry2, Strategy const & strategy)
|
Type |
Concept |
Name |
Description |
|---|---|---|---|
|
Geometry1 const & |
Any type fulfilling a Geometry Concept |
geometry1 |
A model of the specified concept |
|
Geometry2 const & |
Any type fulfilling a Geometry Concept |
geometry2 |
A model of the specified concept |
|
Strategy const & |
Any type fulfilling a Distance Strategy Concept |
strategy |
The strategy which will be used for point to point distance calculations |
Either
#include <boost/geometry.hpp>
Or
#include <boost/geometry/algorithms/discrete_frechet_distance.hpp>
The function discrete_frechet_distance is not defined
by OGC.
![]() |
Note |
|---|---|
PostGIS contains an algorithm ST_FrechetDistance with similar functionality. See the PostGIS documentation. |
|
Geometries |
Status |
|---|---|
|
Linestring-Linestring |
|
![]() |
Note |
|---|---|
The units of the distance depends on strategy. In order to change the default behavior a user has to create a strategy and pass it explicitly into the algorithm. |
Calculate Similarity between two geometries as the discrete frechet distance between them.
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point.hpp> #include <boost/geometry/geometries/linestring.hpp> int main() { namespace bg = boost::geometry; using point_type = bg::model::point<double, 2, bg::cs::geographic<bg::degree>>; using linestring_type = bg::model::linestring<point_type>; linestring_type ls1, ls2; bg::read_wkt("LINESTRING(0 0,1 1,1 2,2 1,2 2)", ls1); bg::read_wkt("LINESTRING(1 0,0 1,1 1,2 1,3 1)", ls2); bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793); bg::strategy::distance::geographic<> strategy(spheroid); double res = bg::discrete_frechet_distance(ls1, ls2, strategy); std::cout << "Discrete Frechet Distance: " << res << std::endl; return 0; }
Output:
Discrete Frechet Distance: 156874