-
-
Save mattyhall/46fafc61c6e0eb1db35c to your computer and use it in GitHub Desktop.
osmxml helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn parse_relation(&mut self, attrs: sax::Attributes) -> ParseResult { | |
let id = try!(self.parse_int_attr("id", attrs)); | |
let mut tags = HashMap::new(); | |
let mut members = Vec::new(); | |
try!(helper(self, "relation", |name, attrs, osm| { | |
match name.as_slice() { | |
"member" => members.push(try!(osm.parse_member(attrs))), | |
"tag" => try!(osm.parse_tag(attrs, &mut tags)), | |
_ => return Err(ParseErr(format!("Relations can only have members and tags. Got {}",name))) | |
} | |
Ok(()) | |
})); | |
self.elements.insert(id, Relation{id: id, members: members, tags: tags}); | |
Ok(()) | |
} | |
fn helper(osm: &mut Osm, tag: &'static str, c: |String, sax::Attributes, &mut Osm| -> ParseResult) -> ParseResult { | |
for event in osm.parser.iter() { | |
match event { | |
Ok(sax::StartElement(name, attrs)) => try!(c(name, attrs, osm)), | |
Ok(sax::EndElement(name)) => { | |
if name.as_slice() == tag.as_slice() { | |
break; | |
} | |
return Err(ParseErr(format!( | |
"Expecting tag to end. Instead got a {}", name))); | |
} | |
_ => () | |
} | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment