mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 10:44:56 +03:00
handle .osm with missing bounds and no clip
This commit is contained in:
parent
1b993544ab
commit
2979f8117f
@ -83,6 +83,15 @@ pub fn read(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
"node" => {
|
"node" => {
|
||||||
|
if doc.gps_bounds == GPSBounds::new() {
|
||||||
|
timer.warn(
|
||||||
|
"No clipping polygon provided and the .osm is missing a <bounds> element, \
|
||||||
|
so figuring out the bounds manually."
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
doc.gps_bounds = scrape_bounds(&tree);
|
||||||
|
}
|
||||||
|
|
||||||
let id = NodeID(obj.attribute("id").unwrap().parse::<i64>().unwrap());
|
let id = NodeID(obj.attribute("id").unwrap().parse::<i64>().unwrap());
|
||||||
if doc.nodes.contains_key(&id) {
|
if doc.nodes.contains_key(&id) {
|
||||||
return Err(format!("Duplicate {}, your .osm is corrupt", id).into());
|
return Err(format!("Duplicate {}, your .osm is corrupt", id).into());
|
||||||
@ -191,6 +200,19 @@ fn read_tags(obj: roxmltree::Node) -> Tags {
|
|||||||
tags
|
tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn scrape_bounds(doc: &roxmltree::Document) -> GPSBounds {
|
||||||
|
let mut b = GPSBounds::new();
|
||||||
|
for obj in doc.descendants() {
|
||||||
|
if obj.is_element() && obj.tag_name().name() == "node" {
|
||||||
|
b.update(LonLat::new(
|
||||||
|
obj.attribute("lon").unwrap().parse::<f64>().unwrap(),
|
||||||
|
obj.attribute("lat").unwrap().parse::<f64>().unwrap(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
||||||
pub struct NodeID(pub i64);
|
pub struct NodeID(pub i64);
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
||||||
|
Loading…
Reference in New Issue
Block a user