pub struct OsmPbfReader<R> { /* private fields */ }
Expand description

The object to manage a pbf file.

Implementations§

source§

impl<R: Read> OsmPbfReader<R>

source

pub fn new(r: R) -> OsmPbfReader<R>

Creates an OsmPbfReader from a Read object.

source

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);
}
source

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);
}
source

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);
source

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.

source

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);
}
source

pub fn into_inner(self) -> R

Extract the Read object.

Consumes the object.

source

pub fn blobs(&mut self) -> Blobs<'_, R>

Returns an iterator on the blobs of the pbf file.

source

pub fn primitive_blocks(&mut self) -> PrimitiveBlocks<'_, R>

Returns an iterator on the blocks of the pbf file.

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for OsmPbfReader<R>where R: RefUnwindSafe,

§

impl<R> Send for OsmPbfReader<R>where R: Send,

§

impl<R> Sync for OsmPbfReader<R>where R: Sync,

§

impl<R> Unpin for OsmPbfReader<R>where R: Unpin,

§

impl<R> UnwindSafe for OsmPbfReader<R>where R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.