A Rust library for reading the OpenStreetMap PBF file format (*.osm.pbf).

123456789101112131415161718192021222324252627282930
  1. // Count the number of nodes, ways and relations in a PBF file given as the
  2. // first command line argument.
  3. extern crate osmpbf;
  4. use osmpbf::*;
  5. fn main() {
  6. let arg = std::env::args_os().nth(1).expect("need a *.osm.pbf file as argument");
  7. let path = std::path::Path::new(&arg);
  8. let reader = ElementReader::from_path(path).unwrap();
  9. println!("Counting...");
  10. let result = reader.par_map_reduce(
  11. |element| {
  12. match element {
  13. Element::Node(_) | Element::DenseNode(_) => (1, 0, 0),
  14. Element::Way(_) => (0, 1, 0),
  15. Element::Relation(_) => (0, 0, 1),
  16. }
  17. },
  18. || (0u64, 0u64, 0u64),
  19. |a, b| (a.0 + b.0, a.1 + b.1, a.2 + b.2)
  20. ).unwrap();
  21. println!("Nodes: {}", result.0);
  22. println!("Ways: {}", result.1);
  23. println!("Relations: {}", result.2);
  24. }