Struct osmpbf::indexed::IndexedReader[][src]

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

Allows filtering elements and iterating over their dependencies. It chooses an efficient method for navigating the PBF structure to achieve this in reasonable time and with reasonable memory.

Implementations

Creates a new IndexedReader.

Example
use osmpbf::*;

let f = std::fs::File::open("tests/test.osm.pbf")?;
let buf_reader = std::io::BufReader::new(f);

let reader = IndexedReader::new(buf_reader)?;

Initializes the index of the PBF structure without decompressing the blobs. You do not need to call this method explicitly as the other methods already take care of it.

Filter ways using a closure and return matching ways and their dependent nodes (Nodes and DenseNodes) in another closure. This method also creates a lightweight in-memory index that speeds up future invocations of this or any other method of IndexedReader.

Example
use osmpbf::*;

let mut reader = IndexedReader::from_path("tests/test.osm.pbf")?;
let mut ways = 0;
let mut nodes = 0;

// Filter all ways that are buildings and count their nodes.
reader.read_ways_and_deps(
    |way| {
        // Filter ways. Return true if tags contain "building": "yes".
        way.tags().any(|key_value| key_value == ("building", "yes"))
    },
    |element| {
        // Increment counter
        match element {
            Element::Way(way) => ways += 1,
            Element::Node(node) => nodes += 1,
            Element::DenseNode(dense_node) => nodes += 1,
            Element::Relation(_) => (), // should not occur
        }
    },
)?;

println!("ways:  {}\nnodes: {}", ways, nodes);

Decodes the PBF structure sequentially and calls the given closure on each node. This method also creates a lightweight in-memory index that speeds up future invocations of this or any other method of IndexedReader.

Errors

Returns the first Error encountered while parsing the PBF structure.

Example
use osmpbf::*;

let mut reader = IndexedReader::from_path("tests/test.osm.pbf")?;
let mut nodes = 0;

reader.for_each_node(
    |element| {
        match element {
            Element::Node(node) => nodes += 1,
            Element::DenseNode(dense_node) => nodes += 1,
            _ => {}
        }
    },
)?;

println!("nodes: {}", nodes);

Creates a new IndexedReader from a given path.

Example
use osmpbf::*;

let reader = IndexedReader::from_path("tests/test.osm.pbf")?;

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 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.