Struct osmpbfreader::reader::OsmPbfReader
source · pub struct OsmPbfReader<R> { /* private fields */ }
Expand description
The object to manage a pbf file.
Implementations§
source§impl<R: Read> OsmPbfReader<R>
impl<R: Read> OsmPbfReader<R>
sourcepub fn new(r: R) -> OsmPbfReader<R>
pub fn new(r: R) -> OsmPbfReader<R>
Creates an OsmPbfReader from a Read object.
sourcepub fn iter(&mut self) -> Iter<'_, R> ⓘ
pub 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);
}
sourcepub fn par_iter(&mut self) -> ParIter<'_, R> ⓘ
pub fn par_iter(&mut self) -> ParIter<'_, 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.
Example
let mut pbf = osmpbfreader::OsmPbfReader::new(std::io::empty());
for obj in pbf.par_iter().map(Result::unwrap) {
println!("{:?}", obj);
}
sourcepub fn rewind(&mut self) -> Result<()>where
R: Seek,
pub 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);
sourcepub fn get_objs_and_deps_store<F, T>(
&mut self,
pred: F,
objects: &mut T
) -> Result<()>where
R: Seek,
F: FnMut(&OsmObj) -> bool,
T: StoreObjs,
pub fn get_objs_and_deps_store<F, T>( &mut self, pred: F, objects: &mut T ) -> Result<()>where R: Seek, F: FnMut(&OsmObj) -> bool, T: StoreObjs,
Same as get_objs_and_deps
but generic.
sourcepub fn get_objs_and_deps<F>(
&mut self,
pred: F
) -> Result<BTreeMap<OsmId, OsmObj>>where
R: Seek,
F: FnMut(&OsmObj) -> bool,
pub 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 their dependencies. The file will be decoded in parallel.
Example
If you want to extract all the administrative boundaries and all their dependencies you can do something like that:
fn is_admin(obj: &osmpbfreader::OsmObj) -> bool {
// get relations with tags[boundary] == administrative
obj.is_relation() && obj.tags().contains("boundary", "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);
}
sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Extract the Read object.
Consumes the object.
sourcepub fn primitive_blocks(&mut self) -> PrimitiveBlocks<'_, R> ⓘ
pub fn primitive_blocks(&mut self) -> PrimitiveBlocks<'_, R> ⓘ
Returns an iterator on the blocks of the pbf file.