[][src]Struct osmpbf::reader::ElementReader

pub struct ElementReader<R: Read> { /* fields omitted */ }

A reader for PBF files that gives access to the stored elements: nodes, ways and relations.

Methods

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

pub fn new(reader: R) -> ElementReader<R>[src]

Creates a new ElementReader.

Example

use osmpbf::*;

let f = std::fs::File::open("tests/test.osm.pbf")?;
let buf_reader = std::io::BufReader::new(f);

let reader = ElementReader::new(buf_reader);

pub fn for_each<F>(self, f: F) -> Result<()> where
    F: for<'a> FnMut(Element<'a>), 
[src]

Decodes the PBF structure sequentially and calls the given closure on each element. Consider using par_map_reduce instead if you need better performance.

Errors

Returns the first Error encountered while parsing the PBF structure.

Example

use osmpbf::*;

let reader = ElementReader::from_path("tests/test.osm.pbf")?;
let mut ways = 0_u64;

// Increment the counter by one for each way.
reader.for_each(|element| {
    if let Element::Way(_) = element {
        ways += 1;
    }
})?;

println!("Number of ways: {}", ways);

pub fn par_map_reduce<MP, RD, ID, T>(
    self,
    map_op: MP,
    identity: ID,
    reduce_op: RD
) -> Result<T> where
    MP: for<'a> Fn(Element<'a>) -> T + Sync + Send,
    RD: Fn(T, T) -> T + Sync + Send,
    ID: Fn() -> T + Sync + Send,
    T: Send
[src]

Parallel map/reduce. Decodes the PBF structure in parallel, calls the closure map_op on each element and then reduces the number of results to one item with the closure reduce_op. Similarly to the init argument in the fold method on iterators, the identity closure should produce an identity value that is inserted into reduce_op when necessary. The number of times that this identity value is inserted should not alter the result.

Errors

Returns the first Error encountered while parsing the PBF structure.

Example

use osmpbf::*;

let reader = ElementReader::from_path("tests/test.osm.pbf")?;

// Count the ways
let ways = reader.par_map_reduce(
    |element| {
        match element {
            Element::Way(_) => 1,
            _ => 0,
        }
    },
    || 0_u64,      // Zero is the identity value for addition
    |a, b| a + b   // Sum the partial results
)?;

println!("Number of ways: {}", ways);

impl ElementReader<BufReader<File>>[src]

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>[src]

Tries to open the file at the given path and constructs an ElementReader from this.

Errors

Returns the same errors that std::fs::File::open returns.

Example

use osmpbf::*;

let reader = ElementReader::from_path("tests/test.osm.pbf")?;

Trait Implementations

impl<R: Clone + Read> Clone for ElementReader<R>[src]

impl<R: Debug + Read> Debug for ElementReader<R>[src]

Auto Trait Implementations

impl<R> RefUnwindSafe for ElementReader<R> where
    R: RefUnwindSafe

impl<R> Send for ElementReader<R> where
    R: Send

impl<R> Sync for ElementReader<R> where
    R: Sync

impl<R> Unpin for ElementReader<R> where
    R: Unpin

impl<R> UnwindSafe for ElementReader<R> where
    R: UnwindSafe

Blanket Implementations

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

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

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

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.

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.