MCPcopy Index your code
hub / github.com/boxdot/osmflat-rs

github.com/boxdot/osmflat-rs @v0.3.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.3.1 ↗ · + Follow
231 symbols 625 edges 19 files 27 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

osmflat

berlin-features

Flat OpenStreetMap (OSM) data format providing an efficient random data access through memory mapped files.

The data format is described and implemented in flatdata. The schema describes the fundamental OSM data structures: nodes, ways, relations and tags as simple non-nested data structures. The relations between these are expressed through indexes.

Compiler

Besides the library for working with osmflat archives, the crate osmflatc contains an OSM pbf format to osmflat data compiler.

To compile OSM data from pbf to osmflat use:

cargo run --release -- input.osm.pbf output.osm.flatdata

The output is a flatdata which is a directory consisting of several files. The schema is also part of the archive. It is checked every time the archive is opened. This guarantees that the compiler which was used to produce the archive fits to the schema used for reading it. The archive data is not compressed.

Using data

You can use any flatdata supported language for reading an osmflat archive. For reading the data in Rust, we provide the osmflat crate.

First, add this to your Cargo.toml:

[dependencies]
osmflat = "0.3.0"

Now, you can open an osmflat archive as any other flatdata archive and read its data:

use osmflat::{FileResourceStorage, Osm};

fn main() {
    let storage = FileResourceStorage::new("path/to/archive.osm.flatdata");
    let archive = Osm::open(storage).unwrap();

    for node in archive.nodes().iter() {
        println!("{:?}", node);
    }
}

Examples

Check the osmflat/examples directory. Feel free to add another example, if you have an idea what to do with the amazing OSM data in few lines of code. 😁

The above map was rendered by osmflat/examples/roads2png.rs in ~ 170 loc from the osmflat archive based on the latest Berlin OSM data.

License

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)

The files src/proto/fileformat.proto and src/proto/osmformat.proto are copies from the OSM-binary project and are under the LGPLv3 license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this document by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Core symbols most depended-on inside this repo

read
called by 18
osmflatc/src/osmpbf.rs
get
called by 15
osmflatc/src/ids.rs
into_iter
called by 10
osmflat/examples/render-features.rs
close
called by 9
osmflatc/src/main.rs
insert
called by 9
osmflatc/src/strings.rs
build
called by 7
osmflatc/src/ids.rs
as_bytes
called by 7
osmflatc/src/strings.rs
next_index
called by 6
osmflatc/src/main.rs

Shape

Method 129
Function 52
Class 44
Enum 6

Languages

Rust100%

Modules by API surface

osmflat/src/osmflat_generated.rs109 symbols
osmflatc/src/main.rs23 symbols
osmflat/examples/render-features.rs18 symbols
osmflatc/src/ids.rs14 symbols
osmflat/examples/render-roads.rs14 symbols
osmflatc/src/strings.rs13 symbols
osmflatc/src/osmpbf.rs12 symbols
osmflat/examples/debug.rs9 symbols
osmflat/src/tags.rs4 symbols
osmflat/examples/road-length.rs4 symbols
osmflatc/src/stats.rs3 symbols
osmflat/examples/cities.rs2 symbols

For agents

$ claude mcp add osmflat-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page