diff options
Diffstat (limited to 'server/src/datex2.cpp')
| -rw-r--r-- | server/src/datex2.cpp | 62 |
1 files changed, 47 insertions, 15 deletions
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( | |||
| 51 | } | 51 | } |
| 52 | auto const pos_list_str = | 52 | auto const pos_list_str = |
| 53 | std::string_view{loc_gml_xml.child_value("loc:posList")}; | 53 | std::string_view{loc_gml_xml.child_value("loc:posList")}; |
| 54 | // lat1 long1 lat2 long2 ... lat(n-1) long(n-1) latn longn | 54 | // lat1 lon1 lat2 lon2 ... lat(n-1) lon(n-1) latn lonn |
| 55 | 55 | ||
| 56 | auto ls = std::make_shared<geo::linestring>(); | 56 | auto ls = std::make_shared<geo::utm::zonable_wgs84_linestring>(); |
| 57 | 57 | ||
| 58 | auto lat_set = false; | 58 | auto lat_set = false; |
| 59 | auto lat = 0.0; | 59 | auto lat = 0.0; |
| 60 | for (auto const lat_or_long_str : std::views::split(pos_list_str, " "sv)) | 60 | for (auto const lat_or_lon_str : std::views::split(pos_list_str, " "sv)) |
| 61 | { | 61 | { |
| 62 | auto mlat_or_long = util::parse_double(std::string_view{lat_or_long_str}); | 62 | auto mlat_or_lon = util::parse_double(std::string_view{lat_or_lon_str}); |
| 63 | if (!mlat_or_long) | 63 | if (!mlat_or_lon) |
| 64 | { | 64 | { |
| 65 | warnings_.insert( | 65 | warnings_.insert( |
| 66 | std::format( | 66 | std::format( |
| 67 | "failed to parse coordinate {:?}", | 67 | "failed to parse coordinate {:?}", |
| 68 | std::string_view{lat_or_long_str})); | 68 | std::string_view{lat_or_lon_str})); |
| 69 | return; | 69 | return; |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | if (!lat_set) | 72 | if (!lat_set) |
| 73 | { | 73 | { |
| 74 | lat = *mlat_or_long; | 74 | lat = *mlat_or_lon; |
| 75 | lat_set = true; | 75 | lat_set = true; |
| 76 | } | 76 | } |
| 77 | else | 77 | else |
| 78 | { | 78 | { |
| 79 | bgeo::append(*ls, geo::point{*mlat_or_long, lat}); | 79 | auto mp = geo::utm::zonable_wgs84_point::from( |
| 80 | geo::wgs84::normalized_point{geo::wgs84::from_lat_lon( | ||
| 81 | lat, *mlat_or_lon)}); | ||
| 82 | if (!mp) | ||
| 83 | warnings_.insert( | ||
| 84 | std::format( | ||
| 85 | "point ({}, {}) outside of UTM range; ignoring it", lat, | ||
| 86 | *mlat_or_lon)); | ||
| 87 | else | ||
| 88 | bgeo::append(*ls, *mp); | ||
| 80 | lat = 0; | 89 | lat = 0; |
| 81 | lat_set = false; | 90 | lat_set = false; |
| 82 | } | 91 | } |
| @@ -110,11 +119,24 @@ auto loader::add_location_from_xml( | |||
| 110 | // maar heeft het UML-model van DATEX II v3 het over ETRS 89: | 119 | // maar heeft het UML-model van DATEX II v3 het over ETRS 89: |
| 111 | // https://docs.datex2.eu/_static/data/v3.7/umlmodel/html/EARoot/EA3/EA3/EA5/EA676.htm | 120 | // https://docs.datex2.eu/_static/data/v3.7/umlmodel/html/EARoot/EA3/EA3/EA5/EA676.htm |
| 112 | 121 | ||
| 113 | auto const coords_etrs89 = geo::point{*mlon, *mlat}; | 122 | auto const coords_etrs89 = geo::wgs84::point{*mlon, *mlat}; |
| 114 | auto coords_wgs84 = geo::point{}; | 123 | auto coords_wgs84 = geo::wgs84::point{}; |
| 115 | etrs89_to_wgs84_.forward(coords_etrs89, coords_wgs84); | 124 | etrs89_to_wgs84_.forward(coords_etrs89, coords_wgs84); |
| 116 | 125 | ||
| 117 | rc.relevant_points.push_back(coords_wgs84); | 126 | auto mp = geo::utm::zonable_wgs84_point::from( |
| 127 | geo::wgs84::normalized_point{coords_wgs84}); | ||
| 128 | if (!mp) | ||
| 129 | { | ||
| 130 | warnings_.insert( | ||
| 131 | std::format( | ||
| 132 | "(ETRS89) point ({}, {}) outside of UTM range after " | ||
| 133 | "transformation to WGS 84; ignoring it", | ||
| 134 | *mlat, *mlon)); | ||
| 135 | } | ||
| 136 | else | ||
| 137 | { | ||
| 138 | rc.relevant_points.push_back(*mp); | ||
| 139 | } | ||
| 118 | } | 140 | } |
| 119 | else | 141 | else |
| 120 | { | 142 | { |
| @@ -347,13 +369,23 @@ auto loader::load_situation_publication(std::string const& filename) | |||
| 347 | // het over ETRS 89: | 369 | // het over ETRS 89: |
| 348 | // https://docs.datex2.eu/_static/data/v3.7/umlmodel/html/EARoot/EA3/EA3/EA5/EA676.htm | 370 | // https://docs.datex2.eu/_static/data/v3.7/umlmodel/html/EARoot/EA3/EA3/EA5/EA676.htm |
| 349 | 371 | ||
| 350 | auto const coords_etrs89 = geo::point{*mlon, *mlat}; | 372 | auto const coords_etrs89 = geo::wgs84::point{*mlon, *mlat}; |
| 351 | auto coords_wgs84 = geo::point{}; | 373 | auto coords_wgs84 = geo::wgs84::point{}; |
| 352 | etrs89_to_wgs84_.forward(coords_etrs89, coords_wgs84); | 374 | etrs89_to_wgs84_.forward(coords_etrs89, coords_wgs84); |
| 353 | 375 | ||
| 354 | if (!sit->location) | 376 | auto mp = geo::utm::zonable_wgs84_point::from( |
| 377 | geo::wgs84::normalized_point{coords_wgs84}); | ||
| 378 | if (!mp) | ||
| 379 | { | ||
| 380 | warnings_.insert( | ||
| 381 | std::format( | ||
| 382 | "(ETRS89) point ({}, {}) outside of UTM range after " | ||
| 383 | "transformation to WGS 84; ignoring it", | ||
| 384 | *mlat, *mlon)); | ||
| 385 | } | ||
| 386 | else if (!sit->location) | ||
| 355 | { | 387 | { |
| 356 | sit->location = coords_wgs84; | 388 | sit->location = *mp; |
| 357 | } | 389 | } |
| 358 | } | 390 | } |
| 359 | } | 391 | } |