Struct osmpbf::indexed::IndexedReader [−][src]
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 (Node
s and
DenseNode
s) 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);