roadpack 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- roadpack-0.1.0/.gitignore +10 -0
- roadpack-0.1.0/FORMAT.md +202 -0
- roadpack-0.1.0/LICENSE +21 -0
- roadpack-0.1.0/PKG-INFO +207 -0
- roadpack-0.1.0/README.es.md +188 -0
- roadpack-0.1.0/README.md +185 -0
- roadpack-0.1.0/benchmarks/README.md +181 -0
- roadpack-0.1.0/benchmarks/admin.py +75 -0
- roadpack-0.1.0/benchmarks/compare_maps.py +86 -0
- roadpack-0.1.0/benchmarks/compare_reference.sh +46 -0
- roadpack-0.1.0/benchmarks/download.sh +11 -0
- roadpack-0.1.0/benchmarks/results/admin-colombia.json +207 -0
- roadpack-0.1.0/benchmarks/results/barcelona.json +129 -0
- roadpack-0.1.0/benchmarks/results/berlin.json +129 -0
- roadpack-0.1.0/benchmarks/results/bogota.json +128 -0
- roadpack-0.1.0/benchmarks/results/brazil.json +129 -0
- roadpack-0.1.0/benchmarks/results/buenos-aires.json +129 -0
- roadpack-0.1.0/benchmarks/results/california.json +129 -0
- roadpack-0.1.0/benchmarks/results/canada.json +129 -0
- roadpack-0.1.0/benchmarks/results/colombia.json +128 -0
- roadpack-0.1.0/benchmarks/results/lima.json +129 -0
- roadpack-0.1.0/benchmarks/results/london.json +129 -0
- roadpack-0.1.0/benchmarks/results/madrid.json +129 -0
- roadpack-0.1.0/benchmarks/results/mexico-city.json +129 -0
- roadpack-0.1.0/benchmarks/results/new-york-state.json +129 -0
- roadpack-0.1.0/benchmarks/results/new-york.json +129 -0
- roadpack-0.1.0/benchmarks/results/ottawa.json +129 -0
- roadpack-0.1.0/benchmarks/results/paris.json +129 -0
- roadpack-0.1.0/benchmarks/results/santiago.json +129 -0
- roadpack-0.1.0/benchmarks/results/spain.json +129 -0
- roadpack-0.1.0/benchmarks/results/texas.json +129 -0
- roadpack-0.1.0/benchmarks/results/tokyo.json +129 -0
- roadpack-0.1.0/benchmarks/results/toronto.json +129 -0
- roadpack-0.1.0/benchmarks/results/validation.json +178 -0
- roadpack-0.1.0/benchmarks/results/washington-dc.json +129 -0
- roadpack-0.1.0/benchmarks/run.py +230 -0
- roadpack-0.1.0/benchmarks/validate.py +62 -0
- roadpack-0.1.0/docs/SCALING.md +218 -0
- roadpack-0.1.0/docs/img/hero.png +0 -0
- roadpack-0.1.0/docs/make_hero.py +105 -0
- roadpack-0.1.0/pyproject.toml +59 -0
- roadpack-0.1.0/reader/.gitignore +5 -0
- roadpack-0.1.0/reader/Makefile +19 -0
- roadpack-0.1.0/reader/README.md +91 -0
- roadpack-0.1.0/reader/examples/route.c +170 -0
- roadpack-0.1.0/reader/gmap.c +257 -0
- roadpack-0.1.0/reader/gmap.h +109 -0
- roadpack-0.1.0/reader/gmap_cache.c +82 -0
- roadpack-0.1.0/reader/gmap_cache.h +51 -0
- roadpack-0.1.0/reader/gmap_file.c +68 -0
- roadpack-0.1.0/reader/gmap_file.h +39 -0
- roadpack-0.1.0/reader/gmap_route.c +225 -0
- roadpack-0.1.0/reader/gmap_route.h +77 -0
- roadpack-0.1.0/reader/tests/check.py +143 -0
- roadpack-0.1.0/src/roadpack/__init__.py +2 -0
- roadpack-0.1.0/src/roadpack/__main__.py +3 -0
- roadpack-0.1.0/src/roadpack/arrays.py +30 -0
- roadpack-0.1.0/src/roadpack/ch/__init__.py +4 -0
- roadpack-0.1.0/src/roadpack/ch/build_ch.cpp +101 -0
- roadpack-0.1.0/src/roadpack/ch/builder.py +91 -0
- roadpack-0.1.0/src/roadpack/cli.py +242 -0
- roadpack-0.1.0/src/roadpack/format/__init__.py +6 -0
- roadpack-0.1.0/src/roadpack/format/chunks.py +27 -0
- roadpack-0.1.0/src/roadpack/format/reader.py +192 -0
- roadpack-0.1.0/src/roadpack/format/spec.py +53 -0
- roadpack-0.1.0/src/roadpack/format/writer.py +107 -0
- roadpack-0.1.0/src/roadpack/geo.py +63 -0
- roadpack-0.1.0/src/roadpack/graph/__init__.py +6 -0
- roadpack-0.1.0/src/roadpack/graph/build.py +293 -0
- roadpack-0.1.0/src/roadpack/graph/restrictions.py +251 -0
- roadpack-0.1.0/src/roadpack/osm/__init__.py +5 -0
- roadpack-0.1.0/src/roadpack/osm/loader.py +205 -0
- roadpack-0.1.0/src/roadpack/osm/profiles.py +83 -0
- roadpack-0.1.0/src/roadpack/pipeline.py +55 -0
- roadpack-0.1.0/src/roadpack/preview.py +192 -0
- roadpack-0.1.0/src/roadpack/regions.py +15 -0
- roadpack-0.1.0/src/roadpack/routing/__init__.py +5 -0
- roadpack-0.1.0/src/roadpack/routing/maneuvers.py +142 -0
- roadpack-0.1.0/src/roadpack/routing/search.py +128 -0
- roadpack-0.1.0/src/roadpack/stats.py +97 -0
- roadpack-0.1.0/tests/conftest.py +110 -0
- roadpack-0.1.0/tests/osm_builder.py +75 -0
- roadpack-0.1.0/tests/test_build.py +146 -0
- roadpack-0.1.0/tests/test_cli.py +113 -0
- roadpack-0.1.0/tests/test_format.py +209 -0
- roadpack-0.1.0/tests/test_geo.py +47 -0
- roadpack-0.1.0/tests/test_profiles.py +50 -0
- roadpack-0.1.0/tests/test_reader_c.py +57 -0
- roadpack-0.1.0/tests/test_restrictions.py +322 -0
- roadpack-0.1.0/tests/test_routing.py +119 -0
- roadpack-0.1.0/tests/test_segments.py +105 -0
roadpack-0.1.0/FORMAT.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# The `.gmap` v3 format
|
|
2
|
+
|
|
3
|
+
The road graph of a region, designed to be read from a microSD card with `seek` + `read`: no text parsing and
|
|
4
|
+
**no need to load it in memory**. A device reads it in pages through a small cache. It carries a precomputed
|
|
5
|
+
**contraction hierarchy (CH)** so long routes settle only a few hundred nodes.
|
|
6
|
+
|
|
7
|
+
Everything is **little-endian** (like the ESP32 and most ARM MCUs). Coordinates are integers in degrees × 10⁷
|
|
8
|
+
(≈ 1.1 cm). `0xFFFFFFFF` means "none" in 32-bit references.
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
┌────────┬────────────┬──────────┬──────────────┬──────────┬───────┬────────────┬─────────────┬──────────┐
|
|
12
|
+
│ header │ nodes │ edges │ spatial grid │ geometry │ names │ CH forward │ CH backward │ copies │
|
|
13
|
+
│ 80 B │ 12 B × N+1 │ 28 B × E │ sparse │ variable │ UTF-8 │ │ │ 8 B × K │
|
|
14
|
+
└────────┴────────────┴──────────┴──────────────┴──────────┴───────┴────────────┴─────────────┴──────────┘
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**v3** adds OSM turn restrictions as junction copies (see [Turn restrictions](#turn-restrictions)): two header
|
|
18
|
+
fields at the end and a table at the end of the file. Everything else is where v2 had it, so a v3 reader also
|
|
19
|
+
reads v2 files (version 2, 72-byte header, no copies).
|
|
20
|
+
|
|
21
|
+
Nodes are sorted along a **Z-order (Morton) curve** of their spatial grid cell: what is close on the map, in
|
|
22
|
+
any direction, is close in the file. Edges, geometry and the CH follow the same order, so a device's page
|
|
23
|
+
cache almost always hits.
|
|
24
|
+
|
|
25
|
+
## On the SD card
|
|
26
|
+
|
|
27
|
+
The file is stored **split into 4 MiB chunks** inside a directory: `/maps/<region>/0000.bin`, `0001.bin`, …
|
|
28
|
+
(`roadpack build` writes them next to the `.gmap`). To the device they are one continuous file.
|
|
29
|
+
|
|
30
|
+
Why: the Arduino ESP32 core ships FAT without *fast seek*, and seeking backwards inside a file of hundreds of
|
|
31
|
+
MB walks the whole cluster chain (measured: ~12 ms per read). With 4 MiB chunks the seeks are short and few
|
|
32
|
+
files are opened (each open costs ~17 ms on the device).
|
|
33
|
+
|
|
34
|
+
## Header (80 bytes)
|
|
35
|
+
|
|
36
|
+
| Offset | Type | Field | Notes |
|
|
37
|
+
|---:|---|---|---|
|
|
38
|
+
| 0 | char[4] | magic | `GMAP` |
|
|
39
|
+
| 4 | u16 | version | `3` |
|
|
40
|
+
| 6 | u16 | header_size | `80` |
|
|
41
|
+
| 8 | u32 | node_count | N |
|
|
42
|
+
| 12 | u32 | edge_count | E |
|
|
43
|
+
| 16 | i32 ×4 | min_lat, min_lon, max_lat, max_lon | extent of the network; (min_lat, min_lon) is the grid origin |
|
|
44
|
+
| 32 | u32 | cell_size | side of a grid cell, in degrees × 10⁷ |
|
|
45
|
+
| 36 | u16 | grid_cols | |
|
|
46
|
+
| 38 | u16 | grid_rows | |
|
|
47
|
+
| 40 | u32 | nodes_off | absolute offset of each section |
|
|
48
|
+
| 44 | u32 | edges_off | |
|
|
49
|
+
| 48 | u32 | grid_off | |
|
|
50
|
+
| 52 | u32 | geom_off | |
|
|
51
|
+
| 56 | u32 | names_off | |
|
|
52
|
+
| 60 | u32 | ch_fwd_off | 4-byte aligned |
|
|
53
|
+
| 64 | u32 | ch_bwd_off | |
|
|
54
|
+
| 68 | u32 | file_size | to check the file is complete |
|
|
55
|
+
| 72 | u32 | copies_off | junction copies (v3; in v2 there are none) |
|
|
56
|
+
| 76 | u32 | copy_count | K |
|
|
57
|
+
|
|
58
|
+
## Nodes (12 bytes, N + 1 records)
|
|
59
|
+
|
|
60
|
+
Each node is an **intersection or the end of a way**, or a **copy** of an intersection (turn restrictions); the
|
|
61
|
+
points along a street are not nodes.
|
|
62
|
+
|
|
63
|
+
| Offset | Type | Field |
|
|
64
|
+
|---:|---|---|
|
|
65
|
+
| 0 | i32 | lat |
|
|
66
|
+
| 4 | i32 | lon |
|
|
67
|
+
| 8 | u32 | first_edge |
|
|
68
|
+
|
|
69
|
+
The edges leaving node `n` are `[first_edge(n), first_edge(n+1))` (CSR layout). Record `N` is a **sentinel**
|
|
70
|
+
with `first_edge = E`.
|
|
71
|
+
|
|
72
|
+
## Edges (28 bytes, E records)
|
|
73
|
+
|
|
74
|
+
**Directed** edges: a two-way road has two (one per direction), a one-way road has one.
|
|
75
|
+
|
|
76
|
+
| Offset | Type | Field | Notes |
|
|
77
|
+
|---:|---|---|---|
|
|
78
|
+
| 0 | u32 | source | source node |
|
|
79
|
+
| 4 | u32 | target | target node |
|
|
80
|
+
| 8 | u32 | geom | offset relative to `geom_off`, or `0xFFFFFFFF` if the segment is straight |
|
|
81
|
+
| 12 | u32 | name | offset relative to `names_off`, or `0xFFFFFFFF` |
|
|
82
|
+
| 16 | u32 | length_m | real length of the segment in meters |
|
|
83
|
+
| 20 | u32 | weight_ds | travel time in tenths of a second (`length_m × 36 / speed_kmh`, at least 1): the routing weight |
|
|
84
|
+
| 24 | u8 | speed_kmh | OSM `maxspeed`, or the default of the road class |
|
|
85
|
+
| 25 | u8 | flags | see below |
|
|
86
|
+
| 26 | u16 | (padding) | 0 |
|
|
87
|
+
|
|
88
|
+
**flags**
|
|
89
|
+
|
|
90
|
+
| Bits | Meaning |
|
|
91
|
+
|---|---|
|
|
92
|
+
| 0-3 | class: 0 motorway, 1 trunk, 2 primary, 3 secondary, 4 tertiary, 5 unclassified, 6 residential, 7 service/living_street |
|
|
93
|
+
| 4 | `GEOM_REVERSED`: the stored geometry runs from target to source; walk it backwards |
|
|
94
|
+
| 5 | `ROUNDABOUT`: the edge is part of a roundabout |
|
|
95
|
+
| 6 | `LINK`: ramp or link road (`*_link`) |
|
|
96
|
+
|
|
97
|
+
## Spatial grid (sparse)
|
|
98
|
+
|
|
99
|
+
A grid of `grid_cols × grid_rows` cells over the extent of the network; only cells with roads are stored (for a
|
|
100
|
+
country, the full grid would take hundreds of MB). The cell of a point is
|
|
101
|
+
`row = (lat - min_lat) / cell_size`, `col = (lon - min_lon) / cell_size`, `id = row * grid_cols + col`.
|
|
102
|
+
|
|
103
|
+
| Type | Field |
|
|
104
|
+
|---|---|
|
|
105
|
+
| u32 | K: number of non-empty cells |
|
|
106
|
+
| u32 × K | cell ids, **sorted** (binary search) |
|
|
107
|
+
| u32 × (K+1) | start of each cell in the edge list |
|
|
108
|
+
| u32 × … | edges: those of cell `k` go from `start[k]` to `start[k+1]` |
|
|
109
|
+
|
|
110
|
+
Each segment appears once per cell it touches (with only one of its two directions). It is used to snap a GPS
|
|
111
|
+
position to the nearest road and to find the streets around a junction.
|
|
112
|
+
|
|
113
|
+
## Geometry
|
|
114
|
+
|
|
115
|
+
Only the **interior points** of a segment (without the end nodes), simplified with Douglas-Peucker at 2 m.
|
|
116
|
+
Both directions of a road share the same geometry.
|
|
117
|
+
|
|
118
|
+
| Type | Field |
|
|
119
|
+
|---|---|
|
|
120
|
+
| u16 | count |
|
|
121
|
+
| u16 | (padding, 0) |
|
|
122
|
+
| (i32 lat, i32 lon) × count | points |
|
|
123
|
+
|
|
124
|
+
Full polyline of an edge = `[source, ...points (reversed if GEOM_REVERSED), target]`.
|
|
125
|
+
|
|
126
|
+
## Names
|
|
127
|
+
|
|
128
|
+
UTF-8 strings terminated by `\0`, without repeats. OSM `name`, or `ref` when the way has no name.
|
|
129
|
+
|
|
130
|
+
## Contraction hierarchy
|
|
131
|
+
|
|
132
|
+
Computed with [RoutingKit](https://github.com/RoutingKit/RoutingKit) on the `weight_ds` weights. Every node
|
|
133
|
+
has a rank; the CH adds **shortcuts** so that every optimal route can be built going up in rank from the start
|
|
134
|
+
and down to the goal.
|
|
135
|
+
|
|
136
|
+
Both sides (forward and backward) share the same structure, **indexed by node number** (not by rank, so the
|
|
137
|
+
CH keeps the Morton locality of the nodes):
|
|
138
|
+
|
|
139
|
+
| Type | Field |
|
|
140
|
+
|---|---|
|
|
141
|
+
| u32 | A: number of arcs |
|
|
142
|
+
| u32 × (N+1) | first_out: arcs of node `n` go from `first_out[n]` to `first_out[n+1]` |
|
|
143
|
+
| 16 B × A | arcs |
|
|
144
|
+
|
|
145
|
+
| Offset | Type | Field | Notes |
|
|
146
|
+
|---:|---|---|---|
|
|
147
|
+
| 0 | u32 | other | forward: the **higher-ranked** node the arc leads to. Backward: the higher-ranked node it comes from (in the real direction of the road, `other → n`) |
|
|
148
|
+
| 4 | u32 | weight_ds | |
|
|
149
|
+
| 8 | u32 | a | if bit 31 is set: original arc, `a & 0x7FFFFFFF` is the edge id. Otherwise: first half of the shortcut (a **backward** arc) |
|
|
150
|
+
| 12 | u32 | b | shortcut: second half (a **forward** arc). Original arc: 0 |
|
|
151
|
+
|
|
152
|
+
**Query** (see `route_ch` in `src/roadpack/routing/search.py`):
|
|
153
|
+
1. Dijkstra from the start over the forward arcs and, interleaved, from the goal over the backward arcs. Each
|
|
154
|
+
side stops when its smallest pending distance can no longer improve the best route found.
|
|
155
|
+
2. The route goes through the meeting node with the smallest sum of distances.
|
|
156
|
+
3. Each arc is unpacked recursively: shortcut = backward(`a`) followed by forward(`b`), down to the original
|
|
157
|
+
edges.
|
|
158
|
+
|
|
159
|
+
In Bogotá and Cundinamarca a query settles about **240 nodes per route** (at most ~400), against thousands for
|
|
160
|
+
A* on the full graph, with exactly the same cost.
|
|
161
|
+
|
|
162
|
+
## Turn restrictions
|
|
163
|
+
|
|
164
|
+
OSM turn restrictions (`type=restriction` relations with a via node or via ways: `no_left_turn`,
|
|
165
|
+
`only_straight_on`, `no_u_turn`, …) are applied by **splitting junctions**, so the graph stays node-based and the hierarchy and its
|
|
166
|
+
query do not change:
|
|
167
|
+
|
|
168
|
+
- At a junction with restrictions, an edge arriving along a restricted way is redirected to a **copy** of the
|
|
169
|
+
junction: same coordinates, and only the exits allowed from that way (copies of the original edges, with their
|
|
170
|
+
own records in the edge table). Arrivals with the same restrictions share a copy; other arrivals keep going to
|
|
171
|
+
the junction itself, which keeps every exit.
|
|
172
|
+
- A restriction with **via ways** (usually the short segment across a median: no U-turn onto the other
|
|
173
|
+
carriageway) becomes a chain of copies: the arrival along the from way leads to a copy of the first junction,
|
|
174
|
+
whose exit along the via way leads to a copy of the next one, and so on; the last copy lacks the forbidden exits.
|
|
175
|
+
Inside the via ways no copy has the exit that turns back along them (otherwise a route could cross the median,
|
|
176
|
+
turn around in the gap and cross again, no longer arriving along the from way). In general the copies are the
|
|
177
|
+
states of an automaton over the edges driven, so restrictions that share junctions combine; a reader needs nothing
|
|
178
|
+
of this: a copy is just a node with its own exits.
|
|
179
|
+
- Copies come **right after their original** in node order (same page of the SD card), and their edges right after
|
|
180
|
+
the original's. The spatial grid lists only original edges.
|
|
181
|
+
|
|
182
|
+
The copies table lists each copy and its original, sorted by copy:
|
|
183
|
+
|
|
184
|
+
| Offset | Type | Field |
|
|
185
|
+
|---:|---|---|
|
|
186
|
+
| 0 | u32 | copy |
|
|
187
|
+
| 4 | u32 | original |
|
|
188
|
+
|
|
189
|
+
What a reader has to do with copies:
|
|
190
|
+
|
|
191
|
+
- **Goal:** a route may arrive at the goal junction through any of its copies (arriving along a restricted way is
|
|
192
|
+
allowed: no turn is made). The backward search starts at the goal and at its copies (those are the nodes right
|
|
193
|
+
after the goal whose original is the goal).
|
|
194
|
+
- **Maneuvers:** the streets of a junction are the exits of the **original**; a forbidden exit is still a street
|
|
195
|
+
the rider sees. Compare junctions by their original.
|
|
196
|
+
- **Snapping a position to a node:** use the original.
|
|
197
|
+
|
|
198
|
+
Not supported (left out when building, and counted): restrictions with several from/to members, or a node and ways
|
|
199
|
+
mixed as via, and time-dependent ones (`restriction:conditional`). If a from or to way goes through the via node
|
|
200
|
+
instead of ending there, which side is meant is ambiguous, and the restriction is skipped; so are via ways that do
|
|
201
|
+
not make a single path of edges from the end of the from way to the to way. `except=*` and
|
|
202
|
+
`restriction:<vehicle>` follow the vehicle profile.
|
roadpack-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NicolasDevel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
roadpack-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: roadpack
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Compact OpenStreetMap road graphs with contraction hierarchies, for routing on microcontrollers
|
|
5
|
+
Project-URL: Repository, https://github.com/NicolasDevel/roadpack
|
|
6
|
+
Author: NicolasDevel
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: contraction-hierarchies,embedded,esp32,offline-navigation,openstreetmap,routing
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
12
|
+
Classifier: Topic :: Software Development :: Embedded Systems
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: osmium>=3.6
|
|
16
|
+
Requires-Dist: pillow
|
|
17
|
+
Provides-Extra: bench
|
|
18
|
+
Requires-Dist: shapely; extra == 'bench'
|
|
19
|
+
Provides-Extra: test
|
|
20
|
+
Requires-Dist: pytest; extra == 'test'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# roadpack
|
|
24
|
+
|
|
25
|
+
[](https://github.com/NicolasDevel/roadpack/actions/workflows/tests.yml)
|
|
26
|
+
[](https://github.com/NicolasDevel/roadpack/blob/main/LICENSE)
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
**Turn-by-turn routing on a microcontroller, offline, for a whole country.**
|
|
30
|
+
|
|
31
|
+
roadpack compiles an OpenStreetMap extract into a `.gmap`: a compact binary road graph with a precomputed
|
|
32
|
+
**contraction hierarchy**, laid out so that a device with a few MB of RAM routes straight from a microSD card,
|
|
33
|
+
without ever loading the map. All of Colombia is 256 MB, turn restrictions included, and an ESP32-S3 finds the 963 km
|
|
34
|
+
route from Bogotá to Cartagena in under 3 seconds, with a cold cache ([on the device](#on-the-device)).
|
|
35
|
+
|
|
36
|
+
[Leer en español](https://github.com/NicolasDevel/roadpack/blob/main/README.es.md)
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
## Why
|
|
41
|
+
|
|
42
|
+
Routing engines like OSRM, Valhalla or GraphHopper are built for servers and phones, with an operating system, a
|
|
43
|
+
file system and plenty of memory. A microcontroller has a few MB of RAM, a FAT-formatted SD card that reads a few
|
|
44
|
+
MB per second, and no operating system. roadpack is not a routing engine: it is the build step that produces a
|
|
45
|
+
map such a device can route on.
|
|
46
|
+
|
|
47
|
+
- **Only what routing needs.** Drivable roads for a vehicle profile; graph nodes only at intersections and dead
|
|
48
|
+
ends (13 to 47 % of the OSM road nodes); shapes simplified to 2 m.
|
|
49
|
+
- **Few nodes per route.** The contraction hierarchy settles a few hundred nodes for a route across a country,
|
|
50
|
+
where A* settles hundreds of thousands (Colombia: 275 against 458,000, median of 200 random routes).
|
|
51
|
+
- **Read in place.** Fixed-size little-endian records, nodes in Z-order so that nearby roads sit in the same SD
|
|
52
|
+
card pages, a sparse spatial grid to snap a GPS fix, and the file split into 4 MiB chunks because FAT without
|
|
53
|
+
fast seek is slow on large files.
|
|
54
|
+
- **Verified.** The hierarchy matches A* on 2,200 random routes across 22 regions, and the builder's output is
|
|
55
|
+
checked against the original reference implementation ([how](https://github.com/NicolasDevel/roadpack/blob/main/docs/SCALING.md)).
|
|
56
|
+
|
|
57
|
+
It was built for, and runs on, an offline motorcycle navigator: a Waveshare ESP32-S3 with a 466×466 round AMOLED
|
|
58
|
+
display, reading the map from a microSD card.
|
|
59
|
+
|
|
60
|
+
## Quick start
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install git+https://github.com/NicolasDevel/roadpack.git
|
|
64
|
+
|
|
65
|
+
# Any extract from https://download.geofabrik.de or https://extract.bbbike.org
|
|
66
|
+
roadpack build colombia-latest.osm.pbf -o out/colombia.gmap # the whole extract
|
|
67
|
+
roadpack build colombia-latest.osm.pbf --region bogota -o out/bogota.gmap # or --bbox minlat,minlon,maxlat,maxlon
|
|
68
|
+
|
|
69
|
+
roadpack info out/bogota.gmap
|
|
70
|
+
roadpack route out/bogota.gmap --from 4.5981,-74.0760 --to 4.6766,-74.0482 --check --images out/preview
|
|
71
|
+
roadpack stats out/bogota.gmap --routes 200
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
Route: 13.9 km, ~19 min, 155 edges, 11 maneuvers
|
|
76
|
+
contraction hierarchy settled 293 nodes in 1 ms (Python)
|
|
77
|
+
A* on the full graph settled 19,263 nodes in 30 ms: same cost
|
|
78
|
+
|
|
79
|
+
0.00 km (+ 0 m) Head out onto Calle 11
|
|
80
|
+
0.55 km (+ 550 m) Turn left onto Avenida Calle 7
|
|
81
|
+
0.67 km (+ 120 m) Turn left onto Carrera 5
|
|
82
|
+
...
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- `build` writes the `.gmap` and the same file split into chunks for the SD card (`out/bogota/0000.bin`, …).
|
|
86
|
+
`--profile car` applies car access and one-way rules instead of motorcycle ones.
|
|
87
|
+
- `route` routes like a device would and prints the maneuvers; `--check` compares with A* on the full graph,
|
|
88
|
+
`--images` renders the route and each maneuver screen.
|
|
89
|
+
- `stats` routes between random pairs of nodes and reports the nodes settled and the KB of the file each route
|
|
90
|
+
reads, which is what the SD card has to deliver.
|
|
91
|
+
|
|
92
|
+
The first build fetches [RoutingKit](https://github.com/RoutingKit/RoutingKit) and compiles a small helper into
|
|
93
|
+
`~/.cache/roadpack`: it needs `git` and a C++17 compiler.
|
|
94
|
+
|
|
95
|
+
## How it works
|
|
96
|
+
|
|
97
|
+
```mermaid
|
|
98
|
+
flowchart LR
|
|
99
|
+
pbf[".osm.pbf"] --> load["Load<br/>highway ways, then their nodes<br/>(two passes, filtered in C++)"]
|
|
100
|
+
load --> graph["Graph<br/>split at intersections<br/>simplify shapes · Z-order<br/>spatial grid<br/>turn restrictions"]
|
|
101
|
+
graph --> ch["Contraction hierarchy<br/>(RoutingKit)"]
|
|
102
|
+
ch --> gmap[".gmap<br/>+ 4 MiB chunks"]
|
|
103
|
+
gmap --> sd["microSD"] --> mcu["Microcontroller<br/>bidirectional upward Dijkstra<br/>through a small page cache"]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
┌────────┬────────────┬──────────┬──────────────┬──────────┬───────┬────────────┬─────────────┐
|
|
108
|
+
│ header │ nodes │ edges │ spatial grid │ geometry │ names │ CH forward │ CH backward │ copies │
|
|
109
|
+
│ 80 B │ 12 B × N+1 │ 28 B × E │ sparse │ variable │ UTF-8 │ │ │ 8 B × K │
|
|
110
|
+
└────────┴────────────┴──────────┴──────────────┴──────────┴───────┴────────────┴─────────────┴──────────┘
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
A device answers a query by running Dijkstra from both ends, only ever going up in the hierarchy, then unpacking
|
|
114
|
+
the shortcuts into real edges. The format, byte by byte, and the query are in [FORMAT.md](https://github.com/NicolasDevel/roadpack/blob/main/FORMAT.md); the Python
|
|
115
|
+
reader in `roadpack.format` and the router in `roadpack.routing` are the reference implementation.
|
|
116
|
+
|
|
117
|
+
## Results
|
|
118
|
+
|
|
119
|
+
From the [benchmarks](https://github.com/NicolasDevel/roadpack/blob/main/benchmarks/README.md): motorcycle profile, 200 random routes per region, on a 16 GB laptop.
|
|
120
|
+
|
|
121
|
+
| Region | Graph nodes | `.gmap` | Build | Median route | Nodes settled (median) | A* settles | KB read per query |
|
|
122
|
+
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
123
|
+
| Bogotá | 91 k | 15 MB | 5 s | 15 km | 272 | 29 k | 1,072 |
|
|
124
|
+
| London | 419 k | 62 MB | 11 s | 31 km | 389 | 83 k | 2,040 |
|
|
125
|
+
| Tokyo | 236 k | 42 MB | 7 s | 17 km | 462 | 81 k | 2,112 |
|
|
126
|
+
| Colombia | 1.27 M | 263 MB | 54 s | 610 km | 294 | 439 k | 2,972 |
|
|
127
|
+
| Spain | 3.41 M | 603 MB | 2 min | 563 km | 420 | 545 k | 3,560 |
|
|
128
|
+
| California | 2.94 M | 505 MB | 95 s | 408 km | 566 | 1.09 M | 4,496 |
|
|
129
|
+
| Brazil | 10.2 M | 2.2 GB | 8 min | 1,674 km | 693 | 3.59 M | 8,020 |
|
|
130
|
+
|
|
131
|
+
The benchmarks also cover Mexico City, Lima, Buenos Aires, Santiago, Washington DC, Ottawa, Toronto, New York,
|
|
132
|
+
Madrid, Barcelona, Paris, Berlin, Canada, Texas, New York State and Colombia by department.
|
|
133
|
+
[How large countries fit in a laptop, and the evidence that they are exact](https://github.com/NicolasDevel/roadpack/blob/main/docs/SCALING.md).
|
|
134
|
+
|
|
135
|
+
## On the device
|
|
136
|
+
|
|
137
|
+
Measured on the navigator this was built for: an ESP32-S3 with a 2 MB page cache in PSRAM (4 KiB pages), reading
|
|
138
|
+
the Colombia map (v3, with turn restrictions; OSM data of 2026-10-27) from a microSD card in 1-bit mode at
|
|
139
|
+
40 MHz, with the cache empty before each route. Median of 10 runs.
|
|
140
|
+
|
|
141
|
+
| Route | Distance | Route found | Ready to navigate | SD card reads |
|
|
142
|
+
|---|---:|---:|---:|---:|
|
|
143
|
+
| Across Bogotá | 15 km | 0.9 s | 1.4 s | 423 |
|
|
144
|
+
| Bogotá – San Francisco | 62 km | 1.0 s | 1.4 s | 464 |
|
|
145
|
+
| Bogotá – Medellín | 427 km | 2.0 s | 2.5 s | 839 |
|
|
146
|
+
| Bogotá – Cartagena | 963 km | 2.9 s | 3.4 s | 1,139 |
|
|
147
|
+
|
|
148
|
+
*Route found* is the hierarchy query plus unpacking the shortcuts into edges. *Ready to navigate* adds the
|
|
149
|
+
shapes and maneuvers of the first 15 km.
|
|
150
|
+
|
|
151
|
+
What made the difference:
|
|
152
|
+
|
|
153
|
+
- **The time is spent waiting for the card.** Each random 4 KiB read costs about 2.8 ms and the computation is
|
|
154
|
+
negligible, so the number to watch is reads per route (what `roadpack stats` reports). Larger pages were slower:
|
|
155
|
+
the cost grows with the bytes read.
|
|
156
|
+
- **Build the shapes as you go.** Reading the shapes and checking every intersection of a 963 km route costs more
|
|
157
|
+
than finding it (1,352 reads), so the navigator only builds 15 km ahead of the rider. Bogotá–Cartagena went from
|
|
158
|
+
8.2 to 4.4 s. Adding up the length of the rest of the route while riding, instead of before showing it, saved
|
|
159
|
+
another ~400 reads: until then the remaining distance is estimated from the travel time of the edges.
|
|
160
|
+
- **Use a genuine card.** A counterfeit one (sold as a known brand, but its CID reports manufacturer 0x6F)
|
|
161
|
+
stalled for about 9 s in one route out of three and sometimes failed a read even after retries. A failed read
|
|
162
|
+
silently leaves zeros where the data should be, so the device counts them and computes the route again. The same
|
|
163
|
+
card once stored a copy of the map with 16 KB of one chunk replaced by other data, without any error: compare
|
|
164
|
+
the files after copying them to the card.
|
|
165
|
+
|
|
166
|
+
## Limits
|
|
167
|
+
|
|
168
|
+
- The `.gmap` format addresses 4 GiB and about 164° of longitude: Brazil fits (2.2 GB); the whole United
|
|
169
|
+
States does not, so it is built per state.
|
|
170
|
+
- Building needs at least about 1.5 GB of RAM, and about 9 GB for Brazil.
|
|
171
|
+
- Turn restrictions with a via node or via ways are applied (in Colombia, 6,826 of 6,940 in the October 2026
|
|
172
|
+
extract); time-dependent ones are not. Speeds come from `maxspeed` or a default per road class (no traffic).
|
|
173
|
+
- The microcontroller side is specified in FORMAT.md, with two implementations: the Python reference here and a
|
|
174
|
+
portable C99 reader and router in [reader/](https://github.com/NicolasDevel/roadpack/blob/main/reader/README.md) (no allocation, checked against the Python one).
|
|
175
|
+
Maneuvers are only in Python for now.
|
|
176
|
+
|
|
177
|
+
## Project layout
|
|
178
|
+
|
|
179
|
+
| Module | Layer |
|
|
180
|
+
|---|---|
|
|
181
|
+
| `roadpack.osm` | Loading: drivable ways of an OSM extract for a vehicle profile (`motorcycle`, `car`) |
|
|
182
|
+
| `roadpack.graph` | Graph: segments between intersections, simplified geometry, Z-order, spatial grid (numpy) |
|
|
183
|
+
| `roadpack.ch` | Contraction hierarchy (RoutingKit, `build_ch.cpp`) |
|
|
184
|
+
| `roadpack.format` | The `.gmap` format: writer, reader, SD card chunks |
|
|
185
|
+
| `roadpack.routing` | Reference routing: CH query, A*, turn-by-turn maneuvers |
|
|
186
|
+
| `roadpack.stats`, `roadpack.preview` | Route sampling; PNG of a route and of each maneuver screen |
|
|
187
|
+
| `benchmarks/` | Benchmark, validation and reference-comparison scripts, with their results |
|
|
188
|
+
| `reader/` | C99 reader and router for microcontrollers ([reader/README.md](https://github.com/NicolasDevel/roadpack/blob/main/reader/README.md)) |
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
pip install -e '.[test]' && pytest
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The tests build small synthetic OpenStreetMap files (a hand-made town that exercises every rule, and random
|
|
195
|
+
street grids) and check, among other things, that the contraction hierarchy matches Dijkstra on every pair of
|
|
196
|
+
nodes.
|
|
197
|
+
|
|
198
|
+
## Licenses
|
|
199
|
+
|
|
200
|
+
- This repository's code: [MIT](https://github.com/NicolasDevel/roadpack/blob/main/LICENSE).
|
|
201
|
+
- Generated maps are a database derived from OpenStreetMap, © OpenStreetMap contributors, under the
|
|
202
|
+
[ODbL](https://opendatacommons.org/licenses/odbl/): if you distribute them, give that attribution and share
|
|
203
|
+
them under the same license.
|
|
204
|
+
- [RoutingKit](https://github.com/RoutingKit/RoutingKit) (BSD 2-Clause) is downloaded and compiled on use; it
|
|
205
|
+
is not included in this repository.
|
|
206
|
+
- Python dependencies: [pyosmium](https://github.com/osmcode/pyosmium) (BSD 2-Clause),
|
|
207
|
+
[NumPy](https://numpy.org) (BSD 3-Clause), [Pillow](https://python-pillow.org) (MIT-CMU).
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# roadpack
|
|
2
|
+
|
|
3
|
+
[](https://github.com/NicolasDevel/roadpack/actions/workflows/tests.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
**Navegación giro a giro en un microcontrolador, sin conexión, para un país entero.**
|
|
8
|
+
|
|
9
|
+
roadpack compila un extracto de OpenStreetMap en un `.gmap`: un grafo vial binario y compacto con una
|
|
10
|
+
**jerarquía de contracción** precalculada, organizado para que un dispositivo con unos pocos MB de RAM rutee
|
|
11
|
+
leyendo directo de una microSD, sin cargar nunca el mapa. Toda Colombia ocupa 256 MB, con las restricciones de
|
|
12
|
+
giro, y un ESP32-S3 encuentra la ruta de 963 km de Bogotá a Cartagena en menos de 3 segundos, con la caché vacía ([en el dispositivo](#en-el-dispositivo)).
|
|
13
|
+
|
|
14
|
+
[Read in English](README.md)
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
## Por qué
|
|
19
|
+
|
|
20
|
+
Motores de ruteo como OSRM, Valhalla o GraphHopper están hechos para servidores y teléfonos, con sistema
|
|
21
|
+
operativo, sistema de archivos y memoria de sobra. Un microcontrolador tiene unos pocos MB de RAM, una tarjeta SD
|
|
22
|
+
en FAT que lee unos pocos MB por segundo y ningún sistema operativo. roadpack no es un motor de ruteo: es el paso
|
|
23
|
+
de compilación que produce un mapa sobre el que ese dispositivo puede rutear.
|
|
24
|
+
|
|
25
|
+
- **Solo lo que el ruteo necesita.** Las vías por las que puede ir el vehículo; nodos del grafo solo en los
|
|
26
|
+
cruces y los finales de vía (del 13 al 47 % de los nodos de vías de OSM); formas simplificadas a 2 m.
|
|
27
|
+
- **Pocos nodos por ruta.** La jerarquía de contracción asienta unos cientos de nodos para cruzar un país, donde
|
|
28
|
+
A* asienta cientos de miles (Colombia: 275 contra 458.000, mediana de 200 rutas al azar).
|
|
29
|
+
- **Se lee en el sitio.** Registros de tamaño fijo en little-endian, nodos en orden de curva Z para que las vías
|
|
30
|
+
cercanas queden en las mismas páginas de la SD, un índice espacial disperso para ubicar la posición del GPS, y
|
|
31
|
+
el archivo partido en pedazos de 4 MiB porque FAT sin *fast seek* es lento con archivos grandes.
|
|
32
|
+
- **Verificado.** La jerarquía coincide con A* en 2.200 rutas al azar de 22 regiones, y la salida del generador
|
|
33
|
+
se compara con la implementación de referencia original ([cómo](docs/SCALING.md), en inglés).
|
|
34
|
+
|
|
35
|
+
Nació para un navegador de moto sin conexión, y funciona en él: una Waveshare ESP32-S3 con pantalla AMOLED
|
|
36
|
+
redonda de 466×466 que lee el mapa de una microSD.
|
|
37
|
+
|
|
38
|
+
## Inicio rápido
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install git+https://github.com/NicolasDevel/roadpack.git
|
|
42
|
+
|
|
43
|
+
# Cualquier extracto de https://download.geofabrik.de o https://extract.bbbike.org
|
|
44
|
+
roadpack build colombia-latest.osm.pbf -o out/colombia.gmap # el extracto completo
|
|
45
|
+
roadpack build colombia-latest.osm.pbf --region bogota -o out/bogota.gmap # o --bbox minlat,minlon,maxlat,maxlon
|
|
46
|
+
|
|
47
|
+
roadpack info out/bogota.gmap
|
|
48
|
+
roadpack route out/bogota.gmap --from 4.5981,-74.0760 --to 4.6766,-74.0482 --check --images out/preview
|
|
49
|
+
roadpack stats out/bogota.gmap --routes 200
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
Route: 13.9 km, ~19 min, 155 edges, 11 maneuvers
|
|
54
|
+
contraction hierarchy settled 293 nodes in 1 ms (Python)
|
|
55
|
+
A* on the full graph settled 19,263 nodes in 30 ms: same cost
|
|
56
|
+
|
|
57
|
+
0.00 km (+ 0 m) Head out onto Calle 11
|
|
58
|
+
0.55 km (+ 550 m) Turn left onto Avenida Calle 7
|
|
59
|
+
0.67 km (+ 120 m) Turn left onto Carrera 5
|
|
60
|
+
...
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- `build` escribe el `.gmap` y el mismo archivo partido en pedazos para la SD (`out/bogota/0000.bin`, …).
|
|
64
|
+
`--profile car` aplica las reglas de acceso y de sentido de los carros en lugar de las de las motos.
|
|
65
|
+
- `route` rutea como lo haría el dispositivo e imprime las maniobras; `--check` compara con A* sobre el grafo
|
|
66
|
+
completo y `--images` dibuja la ruta y la pantalla de cada maniobra.
|
|
67
|
+
- `stats` rutea entre pares de nodos al azar y reporta los nodos asentados y los KB del archivo que lee cada ruta,
|
|
68
|
+
que es lo que la SD tiene que entregar.
|
|
69
|
+
|
|
70
|
+
La primera construcción descarga [RoutingKit](https://github.com/RoutingKit/RoutingKit) y compila un ayudante
|
|
71
|
+
pequeño en `~/.cache/roadpack`: hacen falta `git` y un compilador de C++17.
|
|
72
|
+
|
|
73
|
+
## Cómo funciona
|
|
74
|
+
|
|
75
|
+
```mermaid
|
|
76
|
+
flowchart LR
|
|
77
|
+
pbf[".osm.pbf"] --> load["Carga<br/>vías highway, luego sus nodos<br/>(dos pasadas, filtradas en C++)"]
|
|
78
|
+
load --> graph["Grafo<br/>partido en los cruces<br/>formas simplificadas · curva Z<br/>índice espacial<br/>restricciones de giro"]
|
|
79
|
+
graph --> ch["Jerarquía de contracción<br/>(RoutingKit)"]
|
|
80
|
+
ch --> gmap[".gmap<br/>+ pedazos de 4 MiB"]
|
|
81
|
+
gmap --> sd["microSD"] --> mcu["Microcontrolador<br/>Dijkstra bidireccional hacia arriba<br/>con una caché de páginas pequeña"]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
┌──────────┬────────────┬──────────┬─────────────────┬────────────┬─────────┬────────────┬─────────────┬─────────┐
|
|
86
|
+
│ cabecera │ nodos │ aristas │ índice espacial │ geometría │ nombres │ CH forward │ CH backward │ copias │
|
|
87
|
+
│ 80 B │ 12 B × N+1 │ 28 B × E │ disperso │ variable │ UTF-8 │ │ │ 8 B × K │
|
|
88
|
+
└──────────┴────────────┴──────────┴─────────────────┴────────────┴─────────┴────────────┴─────────────┴─────────┘
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
El dispositivo responde una consulta corriendo Dijkstra desde los dos extremos, subiendo siempre en la
|
|
92
|
+
jerarquía, y luego desarma los atajos en aristas reales. El formato, byte por byte, y la consulta están en
|
|
93
|
+
[FORMAT.md](FORMAT.md) (en inglés); el lector de Python en `roadpack.format` y el ruteo en `roadpack.routing` son
|
|
94
|
+
la implementación de referencia.
|
|
95
|
+
|
|
96
|
+
## Resultados
|
|
97
|
+
|
|
98
|
+
De los [benchmarks](benchmarks/README.md) (en inglés): perfil de moto, 200 rutas al azar por región, en un
|
|
99
|
+
portátil de 16 GB.
|
|
100
|
+
|
|
101
|
+
| Región | Nodos del grafo | `.gmap` | Construcción | Ruta mediana | Nodos asentados (mediana) | A* asienta | KB leídos por consulta |
|
|
102
|
+
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
103
|
+
| Bogotá | 91 mil | 15 MB | 5 s | 15 km | 272 | 29 mil | 1.072 |
|
|
104
|
+
| Londres | 419 mil | 62 MB | 11 s | 31 km | 389 | 83 mil | 2.040 |
|
|
105
|
+
| Tokio | 236 mil | 42 MB | 7 s | 17 km | 462 | 81 mil | 2.112 |
|
|
106
|
+
| Colombia | 1,27 M | 263 MB | 54 s | 610 km | 294 | 439 mil | 2.972 |
|
|
107
|
+
| España | 3,41 M | 603 MB | 2 min | 563 km | 420 | 545 mil | 3.560 |
|
|
108
|
+
| California | 2,94 M | 505 MB | 95 s | 408 km | 566 | 1,09 M | 4.496 |
|
|
109
|
+
| Brasil | 10,2 M | 2,2 GB | 8 min | 1.674 km | 693 | 3,59 M | 8.020 |
|
|
110
|
+
|
|
111
|
+
Los benchmarks también incluyen Ciudad de México, Lima, Buenos Aires, Santiago, Washington DC, Ottawa, Toronto,
|
|
112
|
+
Nueva York, Madrid, Barcelona, París, Berlín, Canadá, Texas, el estado de Nueva York y Colombia por departamento.
|
|
113
|
+
[Cómo caben los países grandes en un portátil, y la evidencia de que los mapas son exactos](docs/SCALING.md).
|
|
114
|
+
|
|
115
|
+
## En el dispositivo
|
|
116
|
+
|
|
117
|
+
Medido en el navegador para el que se hizo: un ESP32-S3 con una caché de páginas de 2 MB en PSRAM (páginas de
|
|
118
|
+
4 KiB), leyendo el mapa de Colombia (v3, con restricciones de giro; datos de OSM del 27-10-2026) de una microSD en
|
|
119
|
+
modo de 1 bit a 40 MHz, con la caché vacía antes de cada ruta. Mediana de 10 corridas.
|
|
120
|
+
|
|
121
|
+
| Ruta | Distancia | Ruta encontrada | Lista para navegar | Lecturas de la SD |
|
|
122
|
+
|---|---:|---:|---:|---:|
|
|
123
|
+
| Bogotá de lado a lado | 15 km | 0,9 s | 1,4 s | 423 |
|
|
124
|
+
| Bogotá – San Francisco | 62 km | 1,0 s | 1,4 s | 464 |
|
|
125
|
+
| Bogotá – Medellín | 427 km | 2,0 s | 2,5 s | 839 |
|
|
126
|
+
| Bogotá – Cartagena | 963 km | 2,9 s | 3,4 s | 1.139 |
|
|
127
|
+
|
|
128
|
+
*Ruta encontrada* es la consulta en la jerarquía más desarmar los atajos en aristas. *Lista para navegar* suma las
|
|
129
|
+
formas y maniobras de los primeros 15 km.
|
|
130
|
+
|
|
131
|
+
Lo que hizo la diferencia:
|
|
132
|
+
|
|
133
|
+
- **El tiempo se va en esperar a la tarjeta.** Cada lectura al azar de 4 KiB cuesta unos 2,8 ms y el cálculo casi
|
|
134
|
+
no pesa, así que lo que hay que mirar son las lecturas por ruta (lo que reporta `roadpack stats`). Las páginas
|
|
135
|
+
más grandes fueron más lentas: el costo crece con los bytes leídos.
|
|
136
|
+
- **Armar las formas sobre la marcha.** Leer las formas y revisar cada cruce de una ruta de 963 km cuesta más que
|
|
137
|
+
encontrarla (1.352 lecturas), así que el navegador solo arma 15 km por delante. Bogotá–Cartagena pasó de 8,2 a
|
|
138
|
+
4,4 s. Sumar el largo del resto de la ruta en marcha, y no antes de mostrarla, ahorró otras ~400 lecturas:
|
|
139
|
+
mientras tanto, la distancia que falta se estima con el tiempo de recorrido de las aristas.
|
|
140
|
+
- **Usar una tarjeta original.** Una falsificada (vendida como de marca conocida, pero su CID dice fabricante 0x6F)
|
|
141
|
+
se frenaba unos 9 s en una de cada tres rutas y a veces fallaba una lectura aun con reintentos. Una lectura
|
|
142
|
+
fallida deja ceros donde iban los datos, sin avisar, así que el dispositivo las cuenta y vuelve a calcular la
|
|
143
|
+
ruta. La misma tarjeta guardó una vez una copia del mapa con 16 KB de un pedazo cambiados por otros datos, sin
|
|
144
|
+
ningún error: hay que comparar los archivos después de copiarlos a la tarjeta.
|
|
145
|
+
|
|
146
|
+
## Límites
|
|
147
|
+
|
|
148
|
+
- El formato `.gmap` direcciona 4 GiB y unos 164° de longitud: Brasil cabe (2,2 GB); Estados Unidos completo
|
|
149
|
+
no, así que se construye por estados.
|
|
150
|
+
- Construir necesita al menos unos 1,5 GB de RAM, y unos 9 GB para Brasil.
|
|
151
|
+
- Se aplican las restricciones de giro con un nodo o con vías como `via` (en Colombia, 6.826 de 6.940 en el
|
|
152
|
+
extracto de octubre de 2026); las que dependen del horario, no. Las velocidades salen de `maxspeed` o de un valor
|
|
153
|
+
por defecto según el tipo de vía (sin tráfico).
|
|
154
|
+
- El lado del microcontrolador está especificado en FORMAT.md, con dos implementaciones: la de referencia en Python y
|
|
155
|
+
un lector y router en C99 portable en [reader/](reader/README.md) (sin memoria dinámica, comparado con el de
|
|
156
|
+
Python). Las maniobras por ahora solo están en Python.
|
|
157
|
+
|
|
158
|
+
## Organización del proyecto
|
|
159
|
+
|
|
160
|
+
| Módulo | Capa |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `roadpack.osm` | Carga: vías de un extracto de OSM aptas para un perfil de vehículo (`motorcycle`, `car`) |
|
|
163
|
+
| `roadpack.graph` | Grafo: tramos entre cruces, geometría simplificada, curva Z, índice espacial (numpy) |
|
|
164
|
+
| `roadpack.ch` | Jerarquía de contracción (RoutingKit, `build_ch.cpp`) |
|
|
165
|
+
| `roadpack.format` | El formato `.gmap`: escritor, lector y pedazos para la SD |
|
|
166
|
+
| `roadpack.routing` | Ruteo de referencia: consulta con la CH, A*, maniobras giro a giro |
|
|
167
|
+
| `roadpack.stats`, `roadpack.preview` | Muestreo de rutas; PNG de una ruta y de la pantalla de cada maniobra |
|
|
168
|
+
| `benchmarks/` | Scripts de benchmarks, validación y comparación con la referencia, con sus resultados |
|
|
169
|
+
| `reader/` | Lector y router en C99 para microcontroladores ([reader/README.md](reader/README.md), en inglés) |
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
pip install -e '.[test]' && pytest
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Las pruebas construyen archivos de OpenStreetMap sintéticos y pequeños (una ciudad hecha a mano que ejercita cada
|
|
176
|
+
regla, y cuadrículas de calles al azar) y verifican, entre otras cosas, que la jerarquía de contracción coincida
|
|
177
|
+
con Dijkstra en todos los pares de nodos.
|
|
178
|
+
|
|
179
|
+
## Licencias
|
|
180
|
+
|
|
181
|
+
- El código de este repositorio: [MIT](LICENSE).
|
|
182
|
+
- Los mapas generados son una base de datos derivada de OpenStreetMap, © colaboradores de OpenStreetMap, bajo la
|
|
183
|
+
[ODbL](https://opendatacommons.org/licenses/odbl/): si se distribuyen, hay que dar esa atribución y compartirlos
|
|
184
|
+
bajo la misma licencia.
|
|
185
|
+
- [RoutingKit](https://github.com/RoutingKit/RoutingKit) (BSD 2-Clause) se descarga y compila al usarlo; no se
|
|
186
|
+
incluye en este repositorio.
|
|
187
|
+
- Dependencias de Python: [pyosmium](https://github.com/osmcode/pyosmium) (BSD 2-Clause),
|
|
188
|
+
[NumPy](https://numpy.org) (BSD 3-Clause), [Pillow](https://python-pillow.org) (MIT-CMU).
|