Core API Reference¶
yoromaps¶
Top-level module with convenience imports.
yoromaps
¶
Yoro Maps — Offline maps, routing, and POI for Africa.
Companion to the yoro geocoding package.
Usage::
import yoromaps
# Build a .yoromaps file for Mali
yoromaps.build("ML", "mali.yoromaps")
# Route between Yoro codes
conn = yoromaps.open_db("mali.yoromaps")
result = yoromaps.route(conn, start_lat=12.6, start_lon=-8.0, end_lat=14.5, end_lon=-4.0)
print(f"{result.distance_km} km, {result.duration_min} min")
# Route from Yoro codes
legs = yoromaps.route_from_codes(conn, ["ML-ABC", "ML-XYZ"])
RouteResult
dataclass
¶
build(country_code, output, pbf_path=None, include_tiles=False, zoom_min=6, zoom_max=12, progress=None)
¶
Build a .yoromaps file for a country.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country_code
|
str
|
ISO country code (e.g. "ML", "BF", "CI"). |
required |
output
|
str | Path
|
Output .yoromaps file path. |
required |
pbf_path
|
str | Path | None
|
Path to an existing PBF file. If None, downloads from Geofabrik. |
None
|
include_tiles
|
bool
|
Also download map tiles (slow, ~200+ MB). |
False
|
zoom_min
|
int
|
Min tile zoom level (if include_tiles). |
6
|
zoom_max
|
int
|
Max tile zoom level (if include_tiles). |
12
|
progress
|
Optional callable(message, current, total). |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created .yoromaps file. |
Source code in src/yoromaps/download.py
open_db(path, create=False)
¶
Open a .yoromaps database. Creates schema if create is True.
Source code in src/yoromaps/db.py
db_config(path)
¶
route(conn, start_lat, start_lon, end_lat, end_lon)
¶
Find the shortest route between two GPS coordinates.
Loads the graph into memory on each call. For multiple routes,
use Graph.from_db() directly.
Source code in src/yoromaps/routing.py
route_from_codes(conn, codes)
¶
Route through multiple Yoro codes in order.
Returns a list of RouteResult, one per leg.
Source code in src/yoromaps/routing.py
yoromaps.routing¶
A* routing engine on the .yoromaps road graph.
yoromaps.routing
¶
A* routing engine on the .yoromaps road graph.
Loads the graph adjacency list into memory for fast routing. Typical memory usage: ~100-200 MB for a country like Mali or Togo.
RouteResult
dataclass
¶
route(conn, start_lat, start_lon, end_lat, end_lon)
¶
Find the shortest route between two GPS coordinates.
Loads the graph into memory on each call. For multiple routes,
use Graph.from_db() directly.
Source code in src/yoromaps/routing.py
route_from_codes(conn, codes)
¶
Route through multiple Yoro codes in order.
Returns a list of RouteResult, one per leg.
Source code in src/yoromaps/routing.py
yoromaps.db¶
Database management for .yoromaps files.
yoromaps.db
¶
Database management for .yoromaps files.
A .yoromaps file is a single SQLite database containing: - tiles: MBTiles-compatible tile storage - nodes: road graph intersections - edges: road graph segments - pois: points of interest - metadata: version, country, timestamps
SCHEMA_VERSION = 1
module-attribute
¶
open_db(path, create=False)
¶
Open a .yoromaps database. Creates schema if create is True.
Source code in src/yoromaps/db.py
db_config(path)
¶
set_metadata(conn, key, value)
¶
yoromaps.download¶
Download OSM data and build .yoromaps files.
yoromaps.download
¶
Download OSM data and build/update a .yoromaps file for a country.
build(country_code, output, pbf_path=None, include_tiles=False, zoom_min=6, zoom_max=12, progress=None)
¶
Build a .yoromaps file for a country.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country_code
|
str
|
ISO country code (e.g. "ML", "BF", "CI"). |
required |
output
|
str | Path
|
Output .yoromaps file path. |
required |
pbf_path
|
str | Path | None
|
Path to an existing PBF file. If None, downloads from Geofabrik. |
None
|
include_tiles
|
bool
|
Also download map tiles (slow, ~200+ MB). |
False
|
zoom_min
|
int
|
Min tile zoom level (if include_tiles). |
6
|
zoom_max
|
int
|
Max tile zoom level (if include_tiles). |
12
|
progress
|
Optional callable(message, current, total). |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created .yoromaps file. |
Source code in src/yoromaps/download.py
download_pbf(country_code, output_dir, progress=None, if_newer_than=None)
¶
Download the latest OSM PBF for a country from Geofabrik.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country_code
|
str
|
ISO country code. |
required |
output_dir
|
str | Path
|
Directory to save the PBF file. |
required |
progress
|
Optional progress callback. |
None
|
|
if_newer_than
|
str | None
|
HTTP date string. Skips download if server file is not newer. |
None
|
Returns:
| Type | Description |
|---|---|
Path | None
|
Path to the downloaded file, or None if skipped (already up to date). |
Source code in src/yoromaps/download.py
yoromaps.tiles¶
MBTiles management — download and serve map tiles.
yoromaps.tiles
¶
MBTiles management — download and serve map tiles from SQLite.
get_tile(conn, z, x, y)
¶
Retrieve a tile from the database (XYZ scheme, converted to TMS internally).
Source code in src/yoromaps/tiles.py
tile_count(conn)
¶
download_tiles(conn, bbox, zoom_min=6, zoom_max=14, tile_url='https://tile.openstreetmap.org/{z}/{x}/{y}.png', progress=None)
¶
Download map tiles for a bounding box into the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Open SQLite connection. |
required |
bbox
|
tuple[float, float, float, float]
|
(lon_min, lat_min, lon_max, lat_max). |
required |
zoom_min
|
int
|
Minimum zoom level. |
6
|
zoom_max
|
int
|
Maximum zoom level. |
14
|
tile_url
|
str
|
Tile URL template with {z}, {x}, {y} placeholders. |
'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
|
progress
|
Optional callable(message, current, total). |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Number of tiles downloaded. |
Source code in src/yoromaps/tiles.py
yoromaps.countries¶
Country registry with Geofabrik download URLs.
yoromaps.countries
¶
Country registry — Geofabrik download URLs and metadata.
Focused on Africa, extensible to other regions.
COUNTRIES = {'ML': Country('ML', 'Mali', 'africa/mali', (-12.5, 10.0, 4.5, 25.0)), 'NE': Country('NE', 'Niger', 'africa/niger', (0.0, 11.5, 16.0, 24.0)), 'BF': Country('BF', 'Burkina Faso', 'africa/burkina-faso', (-5.5, 9.0, 2.5, 15.5)), 'CI': Country('CI', "Cote d'Ivoire", 'africa/ivory-coast', (-8.6, 4.36, -2.49, 10.74)), 'GH': Country('GH', 'Ghana', 'africa/ghana', (-3.26, 4.74, 1.2, 11.17)), 'SN': Country('SN', 'Senegal', 'africa/senegal-and-gambia', (-17.54, 12.31, -11.36, 16.69)), 'GN': Country('GN', 'Guinee', 'africa/guinea', (-15.08, 7.19, -7.64, 12.68)), 'TG': Country('TG', 'Togo', 'africa/togo', (-0.15, 6.1, 1.81, 11.14)), 'BJ': Country('BJ', 'Benin', 'africa/benin', (0.77, 6.14, 3.85, 12.41)), 'NG': Country('NG', 'Nigeria', 'africa/nigeria', (2.69, 4.27, 14.68, 13.89)), 'CM': Country('CM', 'Cameroun', 'africa/cameroon', (8.49, 1.65, 16.19, 13.08)), 'SL': Country('SL', 'Sierra Leone', 'africa/sierra-leone', (-13.3, 6.93, -10.27, 10.0)), 'LR': Country('LR', 'Liberia', 'africa/liberia', (-11.49, 4.35, -7.37, 8.55)), 'MR': Country('MR', 'Mauritanie', 'africa/mauritania', (-17.07, 14.72, -4.83, 27.3)), 'GW': Country('GW', 'Guinee-Bissau', 'africa/guinea-bissau', (-16.71, 10.87, -13.64, 12.68)), 'CD': Country('CD', 'RD Congo', 'africa/congo-democratic-republic', (12.18, -13.46, 31.31, 5.39)), 'KE': Country('KE', 'Kenya', 'africa/kenya', (33.91, -4.68, 41.91, 5.03)), 'TZ': Country('TZ', 'Tanzanie', 'africa/tanzania', (29.33, -11.75, 40.44, -0.99)), 'UG': Country('UG', 'Ouganda', 'africa/uganda', (29.57, -1.48, 35.04, 4.23)), 'ET': Country('ET', 'Ethiopie', 'africa/ethiopia', (32.99, 3.4, 47.99, 14.89)), 'MG': Country('MG', 'Madagascar', 'africa/madagascar', (43.18, -25.61, 50.48, -11.95))}
module-attribute
¶
GEOFABRIK_BASE = 'https://download.geofabrik.de'
module-attribute
¶
Country
dataclass
¶
geofabrik_url(country_code)
¶
Return the Geofabrik PBF download URL for a country.
Source code in src/yoromaps/countries.py
yoromaps.extract¶
OSM PBF extraction into the road graph.
yoromaps.extract
¶
Extract road graph from OSM PBF into a .yoromaps SQLite database.
Uses pyosmium to parse the PBF file in a single pass, extracting highway ways and their nodes into a graph suitable for routing.
HIGHWAY_SPEEDS = {'motorway': 110, 'motorway_link': 60, 'trunk': 90, 'trunk_link': 50, 'primary': 70, 'primary_link': 40, 'secondary': 60, 'secondary_link': 35, 'tertiary': 50, 'tertiary_link': 30, 'residential': 30, 'unclassified': 40, 'living_street': 20, 'service': 20, 'track': 15, 'path': 5}
module-attribute
¶
extract_graph(pbf_path, conn, progress=None)
¶
Extract road graph from a PBF file into the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pbf_path
|
str | Path
|
Path to the .osm.pbf file. |
required |
conn
|
Connection
|
Open SQLite connection to a .yoromaps database. |
required |
progress
|
Optional callable(message, current, total) for progress reporting. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with keys: |
Source code in src/yoromaps/extract.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
haversine(lat1, lon1, lat2, lon2)
¶
Distance in meters between two GPS points.