Struct osmpbfreader::reader::OsmPbfReader[][src]

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

The object to manage a pbf file.

Implementations

impl<R: Read> OsmPbfReader<R>[src]

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

Creates an OsmPbfReader from a Read object.

pub fn iter(&mut self) -> Iter<'_, R>

Notable traits for Iter<'a, R>

impl<'a, R> Iterator for Iter<'a, R> where
    R: Read + 'a, 
type Item = <FlatMap<Blobs<'a, R>, OsmObjs, fn(_: Result<Blob>) -> OsmObjs> as Iterator>::Item;
[src]

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

pub fn par_iter<'a>(&'a mut self) -> ParIter<'a, R>

Notable traits for ParIter<'a, R>

impl<'a, R> Iterator for ParIter<'a, R> where
    R: Read + 'a, 
type Item = <FlatMap<Blobs<'a, R>, OsmObjs, fn(_: Result<Blob>) -> OsmObjs> as Iterator>::Item;
[src]

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

pub fn rewind(&mut self) -> Result<()> where
    R: Seek
[src]

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

pub fn get_objs_and_deps_store<'a, F, T>(
    &mut self,
    pred: F,
    objects: &mut T
) -> Result<()> where
    R: Seek,
    F: FnMut(&OsmObj) -> bool,
    T: StoreObjs
[src]

Same as get_objs_and_deps but generic.

pub fn get_objs_and_deps<F>(
    &mut self,
    pred: F
) -> Result<BTreeMap<OsmId, OsmObj>> where
    R: Seek,
    F: FnMut(&OsmObj) -> bool
[src]

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

pub fn into_inner(self) -> R[src]

Extract the Read object.

Consumes the object.

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

Notable traits for Blobs<'a, R>

impl<'a, R: Read> Iterator for Blobs<'a, R> type Item = Result<Blob>;
[src]

Returns an iterator on the blobs of the pbf file.

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

Notable traits for PrimitiveBlocks<'a, R>

impl<'a, R> Iterator for PrimitiveBlocks<'a, R> where
    R: Read + 'a, 
type Item = <Map<Blobs<'a, R>, fn(_: Result<Blob>) -> Result<PrimitiveBlock>> as Iterator>::Item;
[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.