[][src]Crate osmpbf

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

blob

Read and decode blobs

block

HeaderBlock, PrimitiveBlock and PrimitiveGroups

dense

Iterate over the dense nodes in a PrimitiveGroup

elements

Nodes, ways and relations

mmap_blob

Iterate over blobs from a memory map

reader

High level reader interface

Structs

Error

An error that can occur when reading PBF files.

Enums

BlobError

An error that occurs when decoding a blob.

ErrorKind

The specific type of an error.

Type Definitions

Result

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