From 3e8ce840c70ee00925210b96738696d1dc445f8f Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Tue, 8 Sep 2026 01:36:38 +0200 Subject: UTM projection --- server/src/gpx.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'server/src/gpx.cpp') diff --git a/server/src/gpx.cpp b/server/src/gpx.cpp index 078248f..2193e6a 100644 --- a/server/src/gpx.cpp +++ b/server/src/gpx.cpp @@ -22,7 +22,7 @@ auto qname(std::string_view local) -> xml::qname_view } auto parse_wpt(xml::executor_ref e, xml::attribute_view attrs) - -> xml::parser + -> xml::parser { auto parse_xml_double = [](std::string_view sv) -> std::optional { return util::parse_double(sv, std::chars_format::fixed); }; @@ -43,8 +43,12 @@ auto parse_wpt(xml::executor_ref e, xml::attribute_view attrs) throw std::runtime_error{ "expected valid latitude and longitude for waypoint" }; + auto mp = geo::utm::zonable_wgs84_point::from( + geo::wgs84::normalized_point{geo::wgs84::from_lat_lon(*mlat, *mlon)}); + if (!mp) + throw std::runtime_error{"expected waypoint to be within UTM range"}; co_await xml::ignore_contents(e); - co_return geo::point{*mlon, *mlat}; + co_return *mp; } auto parse_trkseg(xml::executor_ref e, xml::attribute_view) @@ -121,7 +125,7 @@ auto parse_metadata(xml::executor_ref e, xml::attribute_view) } auto parse_wpt(xml::executor_ref e, xml::attribute_view attrs) - -> xml::parser + -> xml::parser { auto parse_xml_double = [](std::string_view sv) -> std::optional { return util::parse_double(sv, std::chars_format::fixed); }; @@ -142,8 +146,12 @@ auto parse_wpt(xml::executor_ref e, xml::attribute_view attrs) throw std::runtime_error{ "expected valid latitude and longitude for waypoint" }; + auto mp = geo::utm::zonable_wgs84_point::from( + geo::wgs84::normalized_point{geo::wgs84::from_lat_lon(*mlat, *mlon)}); + if (!mp) + throw std::runtime_error{"expected waypoint to be within UTM range"}; co_await xml::ignore_contents(e); - co_return geo::point{*mlon, *mlat}; + co_return *mp; } auto parse_trkseg(xml::executor_ref e, xml::attribute_view) -- cgit v1.3