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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*!
  2. A fast reader for the OpenStreetMap PBF file format (\*.osm.pbf).
  3. ## Usage
  4. Add this to your `Cargo.toml`:
  5. ```toml
  6. [dependencies]
  7. osmpbf = "0.1"
  8. ```
  9. and if you're using Rust 2015, add this line to the crate root:
  10. ```rust
  11. extern crate osmpbf;
  12. ```
  13. ## Example: Count ways
  14. Here's a simple example that counts all the OpenStreetMap way elements in a
  15. file:
  16. ```rust
  17. use osmpbf::{ElementReader, Element};
  18. let reader = ElementReader::from_path("tests/test.osm.pbf").unwrap();
  19. let mut ways = 0_u64;
  20. // Increment the counter by one for each way.
  21. reader.for_each(|element| {
  22. if let Element::Way(_) = element {
  23. ways += 1;
  24. }
  25. }).unwrap();
  26. println!("Number of ways: {}", ways);
  27. ```
  28. ## Example: Count ways in parallel
  29. In this second example, we also count the ways but make use of all cores by
  30. decoding the file in parallel:
  31. ```rust
  32. use osmpbf::{ElementReader, Element};
  33. let reader = ElementReader::from_path("tests/test.osm.pbf").unwrap();
  34. // Count the ways
  35. let ways = reader.par_map_reduce(
  36. |element| {
  37. match element {
  38. Element::Way(_) => 1,
  39. _ => 0,
  40. }
  41. },
  42. || 0_u64, // Zero is the identity value for addition
  43. |a, b| a + b // Sum the partial results
  44. ).unwrap();
  45. println!("Number of ways: {}", ways);
  46. ```
  47. */
  48. #![recursion_limit = "1024"]
  49. extern crate byteorder;
  50. extern crate memmap;
  51. extern crate protobuf;
  52. extern crate rayon;
  53. #[cfg(feature = "system-libz")]
  54. extern crate flate2;
  55. #[cfg(not(feature = "system-libz"))]
  56. extern crate inflate;
  57. pub use blob::*;
  58. pub use block::*;
  59. pub use dense::*;
  60. pub use elements::*;
  61. pub use error::{BlobError, Error, ErrorKind, Result};
  62. pub use mmap_blob::*;
  63. pub use reader::*;
  64. pub mod blob;
  65. pub mod block;
  66. pub mod dense;
  67. pub mod elements;
  68. mod error;
  69. pub mod mmap_blob;
  70. mod proto;
  71. pub mod reader;
  72. mod util;