1 // Boost.Geometry
2 // QuickBook Example
3
4 // Copyright (c) 2018, Oracle and/or its affiliates
5 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 //[line_interpolate_strategy
12 //` Shows how to interpolate points on a linestring in geographic coordinate system
13
14 #include <iostream>
15
16 #include <boost/geometry.hpp>
17 #include <boost/geometry/geometries/point_xy.hpp>
18
19 using namespace boost::geometry;
20
main()21 int main()
22 {
23 typedef model::d2::point_xy<double,cs::geographic<degree> > point_type;
24 using segment_type = model::segment<point_type>;
25 using linestring_type = model::linestring<point_type>;
26 using multipoint_type = model::multi_point<point_type>;
27
28 segment_type const s { {0, 0}, {1, 1} };
29 linestring_type const l { {0, 1}, {1, 1}, {1, 2}, {0, 2}, {0, 3} };
30 point_type p;
31 multipoint_type mp;
32 double distance = 50000;
33
34 srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
35 strategy::line_interpolate
36 ::geographic<strategy::vincenty> str(spheroid);
37
38 std::cout << "point interpolation" << std::endl;
39
40 line_interpolate(s, distance, p, str);
41 std::cout << "on segment : " << wkt(p) << std::endl;
42
43 line_interpolate(l, distance, p, str);
44 std::cout << "on linestring : " << wkt(p) << std::endl << std::endl;
45
46 std::cout << "multipoint interpolation" << std::endl;
47
48 line_interpolate(s, distance, mp, str);
49 std::cout << "on segment : " << wkt(mp) << std::endl;
50
51 mp=multipoint_type();
52 line_interpolate(l,distance, mp, str);
53 std::cout << "on linestring : " << wkt(mp) << std::endl;
54
55 return 0;
56 }
57
58 //]
59
60 //[line_interpolate_strategy_output
61 /*`
62 Output:
63 [pre
64 point interpolation
65 on segment : POINT(0.318646 0.31869)
66 on linestring : POINT(0.449226 1.00004)
67
68 multipoint interpolation
69 on segment : MULTIPOINT((0.318646 0.31869),(0.637312 0.63737),(0.956017 0.95603))
70 on linestring : MULTIPOINT((0.449226 1.00004),(0.898451 1.00001),(1 1.34997),
71 (1 1.80215),(0.74722 2.00006),(0.297791 2.00006),(0 2.15257),(0 2.60474))
72 ]
73 */
74 //]
75