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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 indexed::*;
  63. pub use mmap_blob::*;
  64. pub use reader::*;
  65. pub mod blob;
  66. pub mod block;
  67. pub mod dense;
  68. pub mod elements;
  69. mod error;
  70. pub mod indexed;
  71. pub mod mmap_blob;
  72. mod proto;
  73. pub mod reader;
  74. mod util;