Struct osmpbf::reader::ElementReader [−][src]
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);
Trait Implementations
Auto Trait Implementations
impl<R> RefUnwindSafe for ElementReader<R> where
R: RefUnwindSafe,
impl<R> Send for ElementReader<R>
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
Mutably borrows from an owned value. Read more