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 Hausdorff distance between two geometries.
The free function discrete_hausdorff_distance calculates
the discrete Hausdorff distance between two geometries.
template<typename Geometry1, typename Geometry2> auto discrete_hausdorff_distance(Geometry1 const & geometry1, Geometry2 const & geometry2)
|
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 |
Either
#include <boost/geometry.hpp>
Or
#include <boost/geometry/algorithms/discrete_hausdorff_distance.hpp>
The function discrete_hausdorff_distance is not defined
by OGC.
![]() |
Note |
|---|---|
PostGIS contains an algorithm ST_HausdorffDistance with similar functionality. See the PostGIS documentation. |
|
Geometries |
Status |
|---|---|
|
Linestring-Linestring |
|
|
MultiPoint-MultiPoint |
|
|
Point-MultiPoint |
|
|
MultiLineString-MultiLinestring |
|
![]() |
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 hasdorff distance between them.
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/linestring.hpp> int main() { using point_type = boost::geometry::model::d2::point_xy<double>; using linestring_type = boost::geometry::model::linestring<point_type>; linestring_type ls1, ls2; boost::geometry::read_wkt("LINESTRING(0 0,1 1,1 2,2 1,2 2)", ls1); boost::geometry::read_wkt("LINESTRING(1 0,0 1,1 1,2 1,3 1)", ls2); double res = boost::geometry::discrete_hausdorff_distance(ls1, ls2); std::cout << "Discrete Hausdorff Distance: " << res << std::endl; return 0; }
Output:
Discrete Hausdorff Distance: 1.0