CARLA
GeoReferenceParser.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
8 
9 #include "carla/Logging.h"
10 #include "carla/StringUtil.h"
11 #include "carla/geom/GeoLocation.h"
12 #include "carla/road/MapBuilder.h"
13 
14 #include <pugixml/pugixml.hpp>
15 
16 #include <limits>
17 #include <string>
18 #include <vector>
19 
20 namespace carla {
21 namespace opendrive {
22 namespace parser {
23 
24  static double ParseDouble(const std::string &string_value) {
25  return std::stod(string_value);
26  }
27 
28  static geom::GeoLocation ParseGeoReference(const std::string &geo_reference_string) {
29  geom::GeoLocation result{
30  std::numeric_limits<double>::quiet_NaN(),
31  std::numeric_limits<double>::quiet_NaN(),
32  0.0};
33 
34  std::vector<std::string> geo_ref_splitted;
35  StringUtil::Split(geo_ref_splitted, geo_reference_string, " ");
36 
37  for (auto element: geo_ref_splitted) {
38  std::vector<std::string> geo_ref_key_value;
39  StringUtil::Split(geo_ref_key_value, element, "=");
40  if (geo_ref_key_value.size() != 2u) {
41  continue;
42  }
43 
44  if (geo_ref_key_value[0] == "+lat_0") {
45  result.latitude = ParseDouble(geo_ref_key_value[1]);
46  } else if (geo_ref_key_value[0] == "+lon_0") {
47  result.longitude = ParseDouble(geo_ref_key_value[1]);
48  }
49  }
50 
51  if (std::isnan(result.latitude) || std::isnan(result.longitude)) {
52  log_warning("cannot parse georeference: '" + geo_reference_string + "'. Using default values.");
53  result.latitude = 42.0;
54  result.longitude = 2.0;
55  }
56 
57  log_debug("map geo reference: latitude ", result.latitude, ", longitude ", result.longitude);
58 
59  return result;
60  }
61 
63  const pugi::xml_document &xml,
64  carla::road::MapBuilder &map_builder) {
66  xml.child("OpenDRIVE").child("header").child_value("geoReference")));
67  }
68 
69 } // parser
70 } // opendrive
71 } // carla
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
PUGI__FN xpath_string string_value(const xpath_node &na, xpath_allocator *alloc)
Definition: pugixml.cpp:7849
static void log_debug(Args &&...)
Definition: Logging.h:75
static double ParseDouble(const std::string &string_value)
xml_node child(const char_t *name) const
Definition: pugixml.cpp:5490
void SetGeoReference(const geom::GeoLocation &geo_reference)
Definition: MapBuilder.h:361
static void Parse(const pugi::xml_document &xml, carla::road::MapBuilder &map_builder)
static void Split(Container &destination, const Range1T &str, const Range2T &separators)
Definition: StringUtil.h:66
static void log_warning(Args &&... args)
Definition: Logging.h:96
const char_t * child_value() const
Definition: pugixml.cpp:5592
static geom::GeoLocation ParseGeoReference(const std::string &geo_reference_string)