Struct osmpbfreader::reader::OsmPbfReader
[−]
[src]
pub struct OsmPbfReader<R> { /* fields omitted */ }
The object to manage a pbf file.
Methods
impl<R: Read> OsmPbfReader<R>
[src]
fn new(r: R) -> OsmPbfReader<R>
Creates an OsmPbfReader from a Read object.
fn iter(&mut self) -> Iter<R>
Returns an iterator on the OsmObj of the pbf file.
Example
let mut pbf = osmpbfreader::OsmPbfReader::new(std::io::empty()); for obj in pbf.iter().map(Result::unwrap) { println!("{:?}", obj); }
fn par_iter(&mut self) -> Iter<R>
Returns a parallel iterator on the OsmObj of the pbf file.
Several threads decode in parallel the file. The memory and CPU usage are guaranteed to be bounded even if the caller stop consuming items.
Node
The order of the object is not determinist.
Example
let mut pbf = osmpbfreader::OsmPbfReader::new(std::io::empty()); for obj in pbf.par_iter().map(Result::unwrap) { println!("{:?}", obj); }
fn rewind(&mut self) -> Result<()> where R: Seek
Rewinds the pbf file to the begining.
Useful if you want to read several consecutive times the same file.
Example
let mut cursor = std::io::Cursor::new([0, 0, 0]); cursor.set_position(2); let mut pbf = osmpbfreader::OsmPbfReader::new(cursor); pbf.rewind().unwrap(); assert_eq!(pbf.into_inner().position(), 0);
fn get_objs_and_deps<F>(&mut self, pred: F) -> Result<BTreeMap<OsmId, OsmObj>> where R: Seek, F: FnMut(&OsmObj) -> bool
This function give you the ability to find all the objects validating a predicate and all there dependencies. The file will be decoded in parallel.
Example
If you want to extract all the administrative boundaries and all there dependencies you can do something like that:
fn is_admin(obj: &osmpbfreader::OsmObj) -> bool { // get relations with tags[boundary] == administrative obj.relation() .and_then(|rel| rel.tags.get("boundary")) .map_or(false, |v| v == "administrative") } let mut pbf = osmpbfreader::OsmPbfReader::new(std::io::Cursor::new([])); let objs = pbf.get_objs_and_deps(is_admin).unwrap(); for (id, obj) in &objs { println!("{:?}: {:?}", id, obj); }
fn into_inner(self) -> R
Extract the Read object.
Consumes the object.
fn blobs(&mut self) -> Blobs<R>
Returns an iterator on the blobs of the pbf file.
fn primitive_blocks(&mut self) -> PrimitiveBlocks<R>
Returns an iterator on the blocks of the pbf file.