Crate osmpbf

source ·
Expand description

A fast reader for the OpenStreetMap PBF file format (*.osm.pbf).

Usage

Add this to your Cargo.toml:

[dependencies]
osmpbf = "0.1"

and this to your crate root:

extern crate osmpbf;

Example: Count ways

Here’s a simple example that counts all the OpenStreetMap way elements in a file:

extern crate osmpbf;

use osmpbf::*;

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

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

    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::*;

fn main() {
    let reader = ElementReader::from_path("tests/test.osm.pbf").unwrap();

    // 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
    ).unwrap();

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

Re-exports

pub use blob::*;
pub use block::*;
pub use dense::*;
pub use elements::*;
pub use mmap_blob::*;
pub use reader::*;

Modules

Read and decode blobs
HeaderBlock, PrimitiveBlock and PrimitiveGroups
Iterate over the dense nodes in a PrimitiveGroup
Nodes, ways and relations
Iterate over blobs from a memory map
High level reader interface

Structs

An error that can occur when reading PBF files.

Enums

An error that occurs when decoding a blob.
The specific type of an error.

Type Definitions

A type alias for Result<T, osmpbf::Error>.