diff options
Diffstat (limited to 'server/src/geo.cpp')
| -rw-r--r-- | server/src/geo.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/server/src/geo.cpp b/server/src/geo.cpp new file mode 100644 index 0000000..1776f3c --- /dev/null +++ b/server/src/geo.cpp | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | module; | ||
| 2 | |||
| 3 | #include <boost/geometry.hpp> | ||
| 4 | |||
| 5 | module routemon:geo$impl; | ||
| 6 | |||
| 7 | import :geo; | ||
| 8 | |||
| 9 | namespace routemon::geo { | ||
| 10 | |||
| 11 | auto split_linestring_with_overlap_segments( | ||
| 12 | linestring const& ls, double max_split_distance_m, | ||
| 13 | std::vector<linestring>& append_to) -> void | ||
| 14 | { | ||
| 15 | if (bgeo::is_empty(ls)) | ||
| 16 | return; | ||
| 17 | |||
| 18 | auto current_ls = linestring{}; | ||
| 19 | auto current_ls_length = 0.0; | ||
| 20 | auto previous = std::optional<point>{}; | ||
| 21 | bgeo::for_each_point( | ||
| 22 | ls, | ||
| 23 | [&](point p) -> void | ||
| 24 | { | ||
| 25 | bgeo::append(current_ls, p); | ||
| 26 | if (previous) | ||
| 27 | { | ||
| 28 | auto d = bgeo::distance(*previous, p, vincenty_strategy()); | ||
| 29 | current_ls_length += d; | ||
| 30 | if (current_ls_length > max_split_distance_m) | ||
| 31 | { | ||
| 32 | append_to.push_back(std::move(current_ls)); | ||
| 33 | current_ls = linestring{*previous, p}; | ||
| 34 | current_ls_length = d; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | previous = p; | ||
| 38 | }); | ||
| 39 | append_to.emplace_back(std::move(current_ls)); | ||
| 40 | } | ||
| 41 | |||
| 42 | } // namespace routemon::geo | ||