1 // Boost.Geometry
2 // QuickBook Example
3 // Copyright (c) 2018, Oracle and/or its affiliates
4 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 //[discrete_frechet_distance_strategy
10 //` Calculate Similarity between two geometries as the discrete frechet distance between them.
11
12 #include <iostream>
13
14 #include <boost/geometry.hpp>
15 #include <boost/geometry/geometries/point.hpp>
16 #include <boost/geometry/geometries/linestring.hpp>
17
main()18 int main()
19 {
20 namespace bg = boost::geometry;
21 typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > point_type;
22 typedef bg::model::linestring<point_type> linestring_type;
23
24 linestring_type ls1, ls2;
25 bg::read_wkt("LINESTRING(0 0,1 1,1 2,2 1,2 2)", ls1);
26 bg::read_wkt("LINESTRING(1 0,0 1,1 1,2 1,3 1)", ls2);
27
28 bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
29 bg::strategy::distance::geographic<> strategy(spheroid);
30
31 double res = bg::discrete_frechet_distance(ls1, ls2, strategy);
32
33 std::cout << "Discrete Frechet Distance: " << res << std::endl;
34
35 return 0;
36 }
37
38 //]
39
40 //[discrete_frechet_distance_strategy_output
41 /*`
42 Output:
43 [pre
44 Discrete Frechet Distance: 156874
45 ]
46 */
47 //]
48