https://github.com/nextbillion-ai/pbf-craft
A Rust library and command-line tool for reading and writing OpenSteetMap PBF file format.
https://github.com/nextbillion-ai/pbf-craft
encoding-decoding osm parser-library pbf
Last synced: 7 months ago
JSON representation
A Rust library and command-line tool for reading and writing OpenSteetMap PBF file format.
- Host: GitHub
- URL: https://github.com/nextbillion-ai/pbf-craft
- Owner: nextbillion-ai
- License: mit
- Created: 2024-09-17T13:34:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-23T18:35:08.000Z (over 1 year ago)
- Last Synced: 2025-02-01T19:39:26.193Z (over 1 year ago)
- Topics: encoding-decoding, osm, parser-library, pbf
- Language: Rust
- Homepage:
- Size: 1.91 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pbf-craft
A Rust library and command-line tool for reading and writing OpenStreetMap PBF file format.
It contains a variety of PBF readers for a variety of scenarios. For example, a PBF
reader with an index can locate and read elements more efficiently. It also provides
a PBF writer that can write PBF data to a file.
Since this crate uses the btree_cursors feature, it requires you to use the **nightly**
version of rust.
- Written in pure Rust
- Provides an indexing feature to the PBF to greatly improve read performance.
## Example
Reading a PBF file:
```rust
use pbf_craft::readers::PbfReader;
let mut reader = PbfReader::from_path("resources/andorra-latest.osm.pbf").unwrap();
reader.read(|header, element| {
if let Some(header_reader) = header {
// Process header
}
if let Some(element) = element {
// Process element
}
}).unwrap();
```
Finding an element using the index feature. `IndexedReader` creates an index file for the PBF file, which allows you to quickly locate and retrieve an element when looking for it using its ID. `IndexedReader` has an cache option, with which you can fetch a element with its dependencies more efficiently.
```rust
use pbf_craft::models::ElementType;
use pbf_craft::readers::IndexedReader;
let mut indexed_reader = IndexedReader::from_path_with_cache("resources/andorra-latest.osm.pbf", 1000).unwrap();
let node = indexed_reader.find(&ElementType::Node, 12345678).unwrap();
let element_list = indexed_reader.get_with_deps(&ElementType::Way, 1055523837).unwrap();
```
Writing a PBF file:
```rust
use pbf_craft::models::{Element, Node};
use pbf_craft::writers::PbfWriter;
let mut writer = PbfWriter::from_path("resources/output.osm.pbf", true).unwrap();
writer.write(Element::Node(Node::default())).unwrap();
writer.finish().unwrap();
```