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

pub struct ElementReader<R: Read + Send> { /* fields omitted */ }
Expand description

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

Implementations

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

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

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.