handle .osm with missing bounds and no clip

This commit is contained in:
Dustin Carlino 2020-08-01 08:51:19 -07:00
parent 1b993544ab
commit 2979f8117f

View File

@ -83,6 +83,15 @@ pub fn read(
));
}
"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());
if doc.nodes.contains_key(&id) {
return Err(format!("Duplicate {}, your .osm is corrupt", id).into());
@ -191,6 +200,19 @@ fn read_tags(obj: roxmltree::Node) -> 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)]
pub struct NodeID(pub i64);
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]