{"id":22780200,"url":"https://github.com/sitegui/ptolemy","last_synced_at":"2025-04-15T14:42:37.420Z","repository":{"id":36840749,"uuid":"230672442","full_name":"sitegui/ptolemy","owner":"sitegui","description":"A simple engine for shortest path using OpenStreetMap data","archived":false,"fork":false,"pushed_at":"2022-05-27T20:03:52.000Z","size":1864,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T21:21:33.298Z","etag":null,"topics":["openstreetmap","python","routing","rust","shortest-paths"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sitegui.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-28T21:53:52.000Z","updated_at":"2024-10-29T08:46:27.000Z","dependencies_parsed_at":"2022-08-24T21:01:47.585Z","dependency_job_id":null,"html_url":"https://github.com/sitegui/ptolemy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sitegui%2Fptolemy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sitegui%2Fptolemy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sitegui%2Fptolemy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sitegui%2Fptolemy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sitegui","download_url":"https://codeload.github.com/sitegui/ptolemy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249091729,"owners_count":21211394,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["openstreetmap","python","routing","rust","shortest-paths"],"created_at":"2024-12-11T20:12:30.938Z","updated_at":"2025-04-15T14:42:37.378Z","avatar_url":"https://github.com/sitegui.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ptolemy 🗺️🐍🦀\n\nThis project exposes an API that calculates the shortest path in the road network, using data from OpenStreetMap.\n\n## Why\n\nThis a personal adventure with Rust, threads, graphs, memmap and HTTP API. Of course, there are other projects that do more or less the\nsame thing, with different trade-offs and production-readiness, but this one, this one is mine!\n\n## Overview\n\nTODO: show some nices examples\n\n## Project status\n\nIn development, feel free to join! Main features and future roadmap:\n\n- [x] Parse OSM data\n- [x] Generate and serialize graph\n- [x] Ensure the network is strongly-connected\n- [ ] Document graph generation process\n- [x] Load stored data\n- [x] Create shortest-path API\n- [ ] Create parallel distance matrix API\n- [x] Improve serialized data format\n\n## Usage\n\n1. The process starts by downloading the raw OpenStreetMap data. A good source is the pre-packaged data from [GeoFabrik](https://download.geofabrik.de/).\n    You will need the *.osm.pbf format\n2. Execute the `generator` to extract the data from the raw format and create the final graph. For example, for Brazil:\n    ```\n    $ cargo run --release -- generate -i data/brazil-latest.osm.pbf -o data/brazil.ptolemy\n    [   0.0s ( +0.0s)] Will use 16 threads\n    [   0.0s ( +0.0s)] Loaded 17.5k blobs from 835.2MiB\n    [   0.2s ( +0.2s)] File has 16.1k nodes blobs, 1.4k ways blobs and 26 relations blobs\n    [   3.0s ( +2.8s)] Found 6.8M junctions and 23.5M internal nodes from 3.7M ways\n    [   4.4s ( +1.4s)] Loaded info about 30.3M nodes, of which 16.0k are barriers\n    [   6.8s ( +2.4s)] Create graph with 30.3M nodes and 16.8M edges\n    [   9.1s ( +2.3s)] Pruned unreachable nodes\n    [   9.1s ( +0.0s)] Graph now has 6.5M nodes (-23.7M) and 16.4M edges (-355.5k)\n    [  10.5s ( +1.5s)] Weakly-connected components were strongly connected\n    [  10.5s ( +0.0s)] Graph now has 16.5M edges (+70.9k)\n    [  14.9s ( +4.4s)] All smaller components were strongly connected with the main one\n    [  14.9s ( +0.0s)] Graph now has 16.5M edges (+172)\n    [  25.5s (+10.5s)] Wrote results to data/brazil.ptolemy, size = 76.4MiB\n    [  25.5s ( +0.0s)] Done! #DFTBA\n    ```\n3. Execute the `api` to serve the resquests with `cargo run --release -- api -i data/brazil.ptolemy`\n\n## API\n\nThe API is a small and compatible subset of the OSRM API, offering the following endpoints:\n\n### /route\n\nExample:\n\nRequest: `http://localhost:8000/route/v1/driving/-47.015856,-22.938538;-46.555678,-23.110895`\n\n```json\n{\n    \"waypoints\": [{\n        \"location\": [-47.016013, -22.938557],\n        \"distance\": 16.21533725273027\n    }, {\n        \"location\": [-46.555669, -23.110821],\n        \"distance\": 8.279745312178644\n    }],\n    \"routes\": [{\n        \"distance\": 65118,\n        \"geometry\": \"~d_kC`y}}GxHk@ePlA]Zs@r@g@d@kA@iC@gC\\\\qCCq@xAiDlIe@hAQn@On@}CzJe@dRFfGX`HkAZ|A`HwAnIp@DCnDeD|G`@h@oA|Fm@fCmANoAmEs@iBsAkDg@sAs@oBSDeCaAwC_JoAy@yHuGsBuCa@g@kDg\\\\uAmEiCu@{@w@yDuDeI_Is@uA_@@[@m@@uFg@}@MuCc@wBoGUo@{CeI{@eCCiE_AoFb@iDiM@}FYgCYo]mHcASwLiEs[}T|@mNvK_}@`m@itBzVyf@fGel@Ko@WaBeBqNMiAaBmRhzAwbApS}OPe@dCeGjLiy@oAgUG{@_D}YmMaoAdf@idBi@oOCy@O_PxhAq|ApT{_@jMaVnF{IRa@jDaInBmDvHmNJSjKoRtDkHbAoBjTw[va@g\\\\h\\\\yWzF}InAiChMcYzf@{fAlTkkAhCeNrHk[bDaH`AgB`BmD~D_Iv@yArEoI~pAy_Dl@WnJ}Cz~@a`ARUvo@s]jLmZnLkcA`GeNd@gAXo@rT}oChByVF_A`A}Thb@_zCbXo`@jKmOz@oAza@el@nE}G`f@kt@dMwVzMgRzf@_Yx_@_Sn_@{Rt|@mf@bD{D^a@~F}J~DqNpD_TLs@zFm\\\\|C}RzA{LZ_Dd@oELqAtCiaA?qB?i@?wAOoM_AmmAy@ac@y@kSEw@KeCIoBYsIScFAQoCoq@OkEhHkDxAAYtC~M{Bf@BzKpCNHjAbAhBl@tC|@`@JfB`@tC\\\\?Q?q@vEmBhCa@RiE\"\n    }]\n}\n```\n\n## Data format at rest\n\nThe cartography data is stored in a binary and compressed format in a single `.ptolemy` file\n\nIts contents, once decompressed with ZLIB would yield a binary sequence formatted like:\n\n```rs\n{\n    num_nodes: u32,\n    num_edges: u32,\n    node_latitudes: [i32; num_nodes],\n    node_longitudes: [i32; num_nodes],\n    edge_sources: [i32; num_edges],\n    edge_targets: [i32; num_edges],\n    edge_distances: [i32; num_edges],\n    edge_road_levels: [i32; num_edges],\n}\n```\n\nAll the list fields are [delta-encoded](https://en.wikipedia.org/wiki/Delta_encoding) and once decoded will be strictly non-negative. That is, the `i32` is used only to encode possibly decreasing values.\n\nThe nodes are sorted by `(latitude, longitude)` and the edges by `(source, target)`.\n\nBoth latitude and longitude are stored as `1 / 1 000 000` of a degree. The distance is stored in meters and the road level is a value from 0 (main roads) to 5 (smaller roads).\n\n## Development\n\n1. Install [Rust 🦀](https://www.rust-lang.org/tools/install). As of the time of this writing, you'll need the nightly version.\n2. Install [miniconda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html)\n3. Prepare the Python environment with `conda env create` then `conda activate view-graph`\n4. Compile and install the Python native module with `VIRTUAL_ENV=\"$CONDA_PREFIX\" maturin develop -m py_ptolemy/Cargo.toml --release`\n5. Start the notebook server with `jupyter notebook`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsitegui%2Fptolemy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsitegui%2Fptolemy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsitegui%2Fptolemy/lists"}