summaryrefslogtreecommitdiffstats
path: root/server/src/geo.cppm
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/geo.cppm')
-rw-r--r--server/src/geo.cppm59
1 files changed, 34 insertions, 25 deletions
diff --git a/server/src/geo.cppm b/server/src/geo.cppm
index 5cdbdd9..b599ad4 100644
--- a/server/src/geo.cppm
+++ b/server/src/geo.cppm
@@ -8,33 +8,42 @@ export namespace bgeo = boost::geometry;
8 8
9export namespace routemon::geo { 9export namespace routemon::geo {
10 10
11 using point = bgeo::model::point<double, 2, bgeo::cs::spherical_equatorial<bgeo::degree>>; 11using point =
12 using linestring = bgeo::model::linestring<point>; 12 bgeo::model::point<double, 2, bgeo::cs::spherical_equatorial<bgeo::degree>>;
13 using box = bgeo::model::box<point>; 13using linestring = bgeo::model::linestring<point>;
14 using stype = bgeo::srs::spheroid<double>; 14using box = bgeo::model::box<point>;
15 using vincenty_strategy = bgeo::strategy::distance::vincenty<stype>; 15using stype = bgeo::srs::spheroid<double>;
16using vincenty_strategy = bgeo::strategy::distance::vincenty<stype>;
16 17
17 auto split_linestring_with_overlap_segments(linestring const& ls, double max_split_distance_m, std::vector<linestring>& append_to) -> void { 18auto split_linestring_with_overlap_segments(
18 if (bgeo::is_empty(ls)) 19 linestring const& ls, double max_split_distance_m,
19 return; 20 std::vector<linestring>& append_to) -> void
21{
22 if (bgeo::is_empty(ls))
23 return;
20 24
21 auto current_ls = linestring{}; 25 auto current_ls = linestring{};
22 auto current_ls_length = 0.0; 26 auto current_ls_length = 0.0;
23 auto previous = std::optional<point>{}; 27 auto previous = std::optional<point>{};
24 bgeo::for_each_point(ls, [&](point p) -> void { 28 bgeo::for_each_point(
25 bgeo::append(current_ls, p); 29 ls,
26 if (previous) { 30 [&](point p) -> void
27 auto d = bgeo::distance(*previous, p, vincenty_strategy()); 31 {
28 current_ls_length += d; 32 bgeo::append(current_ls, p);
29 if (current_ls_length > max_split_distance_m) { 33 if (previous)
30 append_to.push_back(std::move(current_ls)); 34 {
31 current_ls = linestring{*previous, p}; 35 auto d = bgeo::distance(*previous, p, vincenty_strategy());
32 current_ls_length = d; 36 current_ls_length += d;
37 if (current_ls_length > max_split_distance_m)
38 {
39 append_to.push_back(std::move(current_ls));
40 current_ls = linestring{*previous, p};
41 current_ls_length = d;
42 }
33 } 43 }
34 } 44 previous = p;
35 previous = p; 45 });
36 }); 46 append_to.emplace_back(std::move(current_ls));
37 append_to.emplace_back(std::move(current_ls)); 47}
38 }
39 48
40} // namespace routemon::geo 49} // namespace routemon::geo