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/datex2.cpp | 62 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 15 deletions(-) (limited to 'server/src/datex2.cpp') diff --git a/server/src/datex2.cpp b/server/src/datex2.cpp index 4c8000b..70c5f94 100644 --- a/server/src/datex2.cpp +++ b/server/src/datex2.cpp @@ -51,32 +51,41 @@ auto loader::add_location_from_xml( } auto const pos_list_str = std::string_view{loc_gml_xml.child_value("loc:posList")}; - // lat1 long1 lat2 long2 ... lat(n-1) long(n-1) latn longn + // lat1 lon1 lat2 lon2 ... lat(n-1) lon(n-1) latn lonn - auto ls = std::make_shared(); + auto ls = std::make_shared(); auto lat_set = false; auto lat = 0.0; - for (auto const lat_or_long_str : std::views::split(pos_list_str, " "sv)) + for (auto const lat_or_lon_str : std::views::split(pos_list_str, " "sv)) { - auto mlat_or_long = util::parse_double(std::string_view{lat_or_long_str}); - if (!mlat_or_long) + auto mlat_or_lon = util::parse_double(std::string_view{lat_or_lon_str}); + if (!mlat_or_lon) { warnings_.insert( std::format( "failed to parse coordinate {:?}", - std::string_view{lat_or_long_str})); + std::string_view{lat_or_lon_str})); return; } if (!lat_set) { - lat = *mlat_or_long; + lat = *mlat_or_lon; lat_set = true; } else { - bgeo::append(*ls, geo::point{*mlat_or_long, lat}); + auto mp = geo::utm::zonable_wgs84_point::from( + geo::wgs84::normalized_point{geo::wgs84::from_lat_lon( + lat, *mlat_or_lon)}); + if (!mp) + warnings_.insert( + std::format( + "point ({}, {}) outside of UTM range; ignoring it", lat, + *mlat_or_lon)); + else + bgeo::append(*ls, *mp); lat = 0; lat_set = false; } @@ -110,11 +119,24 @@ auto loader::add_location_from_xml( // maar heeft het UML-model van DATEX II v3 het over ETRS 89: // https://docs.datex2.eu/_static/data/v3.7/umlmodel/html/EARoot/EA3/EA3/EA5/EA676.htm - auto const coords_etrs89 = geo::point{*mlon, *mlat}; - auto coords_wgs84 = geo::point{}; + auto const coords_etrs89 = geo::wgs84::point{*mlon, *mlat}; + auto coords_wgs84 = geo::wgs84::point{}; etrs89_to_wgs84_.forward(coords_etrs89, coords_wgs84); - rc.relevant_points.push_back(coords_wgs84); + auto mp = geo::utm::zonable_wgs84_point::from( + geo::wgs84::normalized_point{coords_wgs84}); + if (!mp) + { + warnings_.insert( + std::format( + "(ETRS89) point ({}, {}) outside of UTM range after " + "transformation to WGS 84; ignoring it", + *mlat, *mlon)); + } + else + { + rc.relevant_points.push_back(*mp); + } } else { @@ -347,13 +369,23 @@ auto loader::load_situation_publication(std::string const& filename) // het over ETRS 89: // https://docs.datex2.eu/_static/data/v3.7/umlmodel/html/EARoot/EA3/EA3/EA5/EA676.htm - auto const coords_etrs89 = geo::point{*mlon, *mlat}; - auto coords_wgs84 = geo::point{}; + auto const coords_etrs89 = geo::wgs84::point{*mlon, *mlat}; + auto coords_wgs84 = geo::wgs84::point{}; etrs89_to_wgs84_.forward(coords_etrs89, coords_wgs84); - if (!sit->location) + auto mp = geo::utm::zonable_wgs84_point::from( + geo::wgs84::normalized_point{coords_wgs84}); + if (!mp) + { + warnings_.insert( + std::format( + "(ETRS89) point ({}, {}) outside of UTM range after " + "transformation to WGS 84; ignoring it", + *mlat, *mlon)); + } + else if (!sit->location) { - sit->location = coords_wgs84; + sit->location = *mp; } } } -- cgit v1.3