#openstreetmap #csv #routing #convert #pbf #graph #friendly

bin+lib osm4routing

Convert OpenStreetMap data into routing friendly CSV

22 releases

0.7.0 Sep 12, 2024
0.6.5 Jul 4, 2024
0.6.3 Jun 12, 2024
0.6.1 Jan 30, 2024
0.2.0 Oct 20, 2016

#19 in Geospatial

Download history 168/week @ 2024-07-18 159/week @ 2024-07-25 56/week @ 2024-08-01 72/week @ 2024-08-08 41/week @ 2024-08-15 56/week @ 2024-08-22 315/week @ 2024-08-29 154/week @ 2024-09-05 287/week @ 2024-09-12 251/week @ 2024-09-19 167/week @ 2024-09-26 588/week @ 2024-10-03 689/week @ 2024-10-10 348/week @ 2024-10-17 249/week @ 2024-10-24 129/week @ 2024-10-31

1,627 downloads per month
Used in 2 crates

MIT license

39KB
906 lines

osm4routing2

This project is a rewrite in rust from https://github.com/Tristramg/osm4routing

It converts an OpenStreetMap file (in the .pbf format) into a CSV file.

Build

Get a rust distribution with cargo: https://www.rust-lang.org/en-US/downloads.html

Run cargo install osm4routing

You can now use osm4routing <some_osmfile.pbf> to generate the nodes.csv and edges.csv that represent the road network.

If you prefer running the application from the sources, and not installing it, you run

cargo run --release -- <path_to_your_osmfile.pbf>

The identifiers for nodes and edges are from OpenStreetMap.

The id property of an edge is unique, while the osm_id can be duplicated.

Importing in a database

If you prefer having the files in database, you can run the very basic import_postgres.sh script.

It supposes that a database osm4routing exists (otherwise modify it to your needs).

Using as a library

In order to use osm4routing as a library, add osm4routing = "*" in your Cargo.toml file in the [dependencies] section.

Use it:

let (nodes, edges) = osm4routing::read("some_data.osm.pbf")?;

If you wand to reject certain edges based on their tag, use the Reader (it also accepts "*" to reject every value):

let (nodes, edges) = osm4routing::Reader::new().reject("area", "yes").read("some_data.osm.pbf")?;

If you want only specific tags, use required; it accepts "*" if any value is accepted; if multiple conditions are given, it will accept any way that matches at least one of the values.

let (nodes, edges) = osm4routing::Reader::new().require("railway", "rail").read("some_data.osm.pbf")?;

If you need to read some tags, pass them to the reader:

let (nodes, edges) = osm4routing::Reader::new().read_tag("highway").read("some_data.osm.pbf")?;

If want to contract edges that come from different OpenStreetMap ways, but where there is no intersection (that can happen when the tags change, e.g. a tunnel):

let (nodes, edges) = osm4routing::Reader::new().merge_ways().read("some_data.osm.pbf")?;

Dependencies

~6MB
~106K SLoC