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.cppm40
1 files changed, 40 insertions, 0 deletions
diff --git a/server/src/geo.cppm b/server/src/geo.cppm
new file mode 100644
index 0000000..5cdbdd9
--- /dev/null
+++ b/server/src/geo.cppm
@@ -0,0 +1,40 @@
1module;
2
3#include <boost/geometry.hpp>
4
5export module routemon:geo;
6
7export namespace bgeo = boost::geometry;
8
9export namespace routemon::geo {
10
11 using point = bgeo::model::point<double, 2, bgeo::cs::spherical_equatorial<bgeo::degree>>;
12 using linestring = bgeo::model::linestring<point>;
13 using box = bgeo::model::box<point>;
14 using stype = bgeo::srs::spheroid<double>;
15 using vincenty_strategy = bgeo::strategy::distance::vincenty<stype>;
16
17 auto split_linestring_with_overlap_segments(linestring const& ls, double max_split_distance_m, std::vector<linestring>& append_to) -> void {
18 if (bgeo::is_empty(ls))
19 return;
20
21 auto current_ls = linestring{};
22 auto current_ls_length = 0.0;
23 auto previous = std::optional<point>{};
24 bgeo::for_each_point(ls, [&](point p) -> void {
25 bgeo::append(current_ls, p);
26 if (previous) {
27 auto d = bgeo::distance(*previous, p, vincenty_strategy());
28 current_ls_length += d;
29 if (current_ls_length > max_split_distance_m) {
30 append_to.push_back(std::move(current_ls));
31 current_ls = linestring{*previous, p};
32 current_ls_length = d;
33 }
34 }
35 previous = p;
36 });
37 append_to.emplace_back(std::move(current_ls));
38 }
39
40} // namespace routemon::geo