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

count.rs 994B

1234567891011121314151617181920212223242526272829303132333435
  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. match 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. ) {
  21. Ok((nodes, ways, relations)) => {
  22. println!("Nodes: {}", nodes);
  23. println!("Ways: {}", ways);
  24. println!("Relations: {}", relations);
  25. },
  26. Err(e) => {
  27. println!("{}", e);
  28. },
  29. }
  30. }