21 const char *key = tag.attribute(
"k").value();
22 const char *value = tag.attribute(
"v").value();
23 if (key !=
nullptr && key[0] !=
'\0') {
24 tags.emplace(key, value !=
nullptr ? value :
"");
34 extent.
south = std::numeric_limits<double>::max();
35 extent.
west = std::numeric_limits<double>::max();
36 extent.
north = std::numeric_limits<double>::lowest();
37 extent.
east = std::numeric_limits<double>::lowest();
38 for (
const auto &entry :
nodes) {
39 extent.
south = std::min(extent.
south, entry.second.lat);
40 extent.
north = std::max(extent.
north, entry.second.lat);
41 extent.
west = std::min(extent.
west, entry.second.lon);
42 extent.
east = std::max(extent.
east, entry.second.lon);
51 throw std::runtime_error(std::string(
"osm: could not parse the document: ") +
56 throw std::runtime_error(
"osm: the document has no <osm> element");
62 parsed.
id =
node.attribute(
"id").as_llong();
63 parsed.
lat =
node.attribute(
"lat").as_double();
64 parsed.
lon =
node.attribute(
"lon").as_double();
66 data.
nodes.emplace(parsed.
id, std::move(parsed));
68 if (data.
nodes.empty()) {
69 throw std::runtime_error(
"osm: the document carries no nodes");
74 parsed.
id = way.attribute(
"id").as_llong();
76 const long long id = ref.attribute(
"ref").as_llong();
77 if (data.
nodes.count(
id) != 0u) {
78 parsed.
nodes.push_back(
id);
81 parsed.
tags = ReadTags(way);
82 if (parsed.
nodes.size() >= 2u) {
83 data.
ways.push_back(std::move(parsed));
87 for (
pugi::xml_node rel = root.
child(
"relation"); rel; rel = rel.next_sibling(
"relation")) {
89 parsed.
id = rel.attribute(
"id").as_llong();
93 entry.
type = member.attribute(
"type").value();
94 entry.
ref = member.attribute(
"ref").as_llong();
95 entry.
role = member.attribute(
"role").value();
96 parsed.
members.push_back(std::move(entry));
98 parsed.
tags = ReadTags(rel);
99 data.
relations.push_back(std::move(parsed));
double as_double(double def=0) const
xml_parse_result load_buffer(const void *contents, size_t size, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
xml_node child(const char_t *name) const
xml_node next_sibling() const
xml_attribute attribute(const char_t *name) const
OsmData ParseOsmXml(const std::string &xml)
Parse an OpenStreetMap XML document.
std::map< std::string, std::string > Tags
const char * description() const
std::vector< OsmRelation > relations
std::vector< OsmWay > ways
BoundingBox NodeExtent() const
Extent of the nodes themselves, used when the file carries no <bounds> or the bounds are smaller than...
std::map< long long, OsmNode > nodes
std::optional< BoundingBox > bbox
std::vector< OsmMember > members
std::vector< long long > nodes