Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world.

discrete_frechet_distance (with strategy)

Calculate discrete Frechet distance between two geometries (currently works for LineString-LineString) using specified strategy.

Synopsis

```template<typename Geometry1, typename Geometry2, typename Strategy>
distance_result< typename point_type<Geometry1>::type, typename point_type<Geometry2>::type, Strategy >::type discrete_frechet_distance(Geometry1 const & geometry1, Geometry2 const & geometry2, Strategy const & strategy)```

Parameters

Type

Concept

Name

Description

Geometry1 const &

Any type fulfilling a Geometry Concept

geometry1

Input geometry

Geometry2 const &

Any type fulfilling a Geometry Concept

geometry2

Input geometry

Strategy const &

A type fulfilling a DistanceStrategy concept

strategy

Distance strategy to be used to calculate Pt-Pt distance

Either

`#include <boost/geometry.hpp>`

Or

`#include <boost/geometry/algorithms/discrete_frechet_distance.hpp>`

Behavior

The algorithm calculate discrete frechet distance between two geometries.

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.
Example

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;
typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > point_type;
typedef bg::model::linestring<point_type> linestring_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
```