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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 this to your 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. extern crate osmpbf;
  18. use osmpbf::*;
  19. fn main() {
  20. let reader = ElementReader::from_path("tests/test.osm.pbf").unwrap();
  21. let mut ways = 0_u64;
  22. // Increment the counter by one for each way.
  23. reader.for_each(|element| {
  24. if let Element::Way(_) = element {
  25. ways += 1;
  26. }
  27. }).unwrap();
  28. println!("Number of ways: {}", ways);
  29. }
  30. ```
  31. ## Example: Count ways in parallel
  32. In this second example, we also count the ways but make use of all cores by
  33. decoding the file in parallel:
  34. ```rust
  35. use osmpbf::*;
  36. fn main() {
  37. let reader = ElementReader::from_path("tests/test.osm.pbf").unwrap();
  38. // Count the ways
  39. let ways = reader.par_map_reduce(
  40. |element| {
  41. match element {
  42. Element::Way(_) => 1,
  43. _ => 0,
  44. }
  45. },
  46. || 0_u64, // Zero is the identity value for addition
  47. |a, b| a + b // Sum the partial results
  48. ).unwrap();
  49. println!("Number of ways: {}", ways);
  50. }
  51. ```
  52. */
  53. #![recursion_limit = "1024"]
  54. extern crate byteorder;
  55. extern crate memmap;
  56. extern crate protobuf;
  57. extern crate rayon;
  58. #[cfg(feature = "system-libz")]
  59. extern crate flate2;
  60. #[cfg(not(feature = "system-libz"))]
  61. extern crate inflate;
  62. pub use blob::*;
  63. pub use block::*;
  64. pub use dense::*;
  65. pub use elements::*;
  66. pub use error::{BlobError, Error, ErrorKind, Result};
  67. pub use mmap_blob::*;
  68. pub use reader::*;
  69. mod error;
  70. mod proto;
  71. pub mod reader;
  72. pub mod blob;
  73. pub mod block;
  74. pub mod dense;
  75. pub mod elements;
  76. pub mod mmap_blob;
  77. mod util;