Expand description
A fast reader for the OpenStreetMap PBF file format (*.osm.pbf).
Usage
Add this to your Cargo.toml
:
[dependencies]
osmpbf = "0.2"
Example: Count ways
Here’s a simple example that counts all the OpenStreetMap way elements in a file:
use osmpbf::{ElementReader, Element};
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);
Example: Count ways in parallel
In this second example, we also count the ways but make use of all cores by decoding the file in parallel:
use osmpbf::{ElementReader, Element};
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);
Re-exports
pub use blob::*;
pub use block::*;
pub use dense::*;
pub use elements::*;
pub use indexed::*;
pub use mmap_blob::*;
pub use reader::*;
Modules
Read and decode blobs
HeaderBlock
, PrimitiveBlock
and PrimitiveGroup
s
Iterate over the dense nodes in a PrimitiveGroup
Nodes, ways and relations
Speed up searches by using an index
Iterate over blobs from a memory map
High level reader interface
Structs
An error that can occur when reading PBF files.
Enums
Type Definitions
A type alias for Result<T, osmpbf::Error>
.