diff options
| author | Rutger Broekhoff | 2026-08-28 18:03:05 +0200 |
|---|---|---|
| committer | Rutger Broekhoff | 2026-08-28 18:03:05 +0200 |
| commit | 973aec43ea54bbf95b64fbcb636403401d1ca60e (patch) | |
| tree | 41b7911c420766a9b463245b9296f44c5bf35258 /server/src/geo.cppm | |
| download | routemon-973aec43ea54bbf95b64fbcb636403401d1ca60e.tar.gz routemon-973aec43ea54bbf95b64fbcb636403401d1ca60e.zip | |
Import from e4b104792206ee7ea64bf39c6b7d2c0c230f9d14
Diffstat (limited to 'server/src/geo.cppm')
| -rw-r--r-- | server/src/geo.cppm | 40 |
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 @@ | |||
| 1 | module; | ||
| 2 | |||
| 3 | #include <boost/geometry.hpp> | ||
| 4 | |||
| 5 | export module routemon:geo; | ||
| 6 | |||
| 7 | export namespace bgeo = boost::geometry; | ||
| 8 | |||
| 9 | export 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 | ||