API Main Roads & Railways
Accesso e limitiPublic, no key needed · Heavy▾
Aperto a tutti. Una chiave API gratuita dal tuo profilo aumenta i limiti: inviarla in un X-API-Key intestazione, o come api_key= nell'indirizzo.
| 5 minuti | Ora | Giorno | |
|---|---|---|---|
| Senza una chiave | 20 | 120 | 500 |
| Con una chiave | 60 | 400 | 2,000 |
Each 100 square km of area counts as one request, so a 10 km square is 1 and a 30 km square is 9.
Accedi per creare una chiave gratuita nella pagina del tuo profilo.
Ogni risposta contiene X-RateLimit-Remaining e X-RateLimit-Reset. Se supera un limite, la risposta è errore 429 con retry_after in secondi. Le richieste rifiutate non vengono conteggiate.
Dove si trovano le strade principali e le ferrovie su un quadrato intorno a un punto, e quali sono: ogni cella di circa 10 metri viene restituita come una di sette classi, dalle autostrade alle ferrovie storiche, gli stessi dati del Mappa Strade e Ferrovie Principali disegna. È inteso come livello di pericolo di atterraggio accanto al Inland Water API, quindi uno strumento di atterraggio può mantenere un margine più ampio da un'autostrada rispetto a una strada tranquilla: richiedilo come JSON per una pagina web o script, oppure come piccolo file binario che un flight computer o una stazione di terra possono portare con sé.
lat lon size_kmParametri
| Parametro | Significato |
|---|---|
lat, lon | Il centro del quadrato, gradi decimali (lng anche accettato) |
size_km | Il lato del quadrato in km, più di 0 e fino a 30. Se omesso, 1. I quadrati superiori a 10 km arrivano come format=bin solo. |
format | Facoltativo. json (il predefinito, per quadrati fino a 10 km) o bin: un'intestazione di 32 byte e le celle, come file, per qualsiasi dimensione. |
compress | Facoltativo. none (l'impostazione predefinita), zlib oppure lzma, come su Inland Water API. |
classes | Facoltativo. Le classi da mantenere, come un elenco ad esempio 1,2,5; every other class comes back as 0. Left out, all seven. |
download | Optional. 1 makes a browser save a format=bin answer as a file, named for the square. |
The classes
| Class | What | OpenStreetMap types |
|---|---|---|
| 0 | Nothing | |
| 1 | Motorway and trunk road | motorway, trunk, and their slip roads |
| 2 | A road | primary and its slip roads |
| 3 | B road | secondary and its slip roads |
| 4 | Tertiary and minor road | tertiary and its slip roads; unclassified (the public minor roads and lanes between villages and farms) |
| 5 | Ferrovia pesante | rotaia |
| 6 | Ferrovia media | ferrovia leggera, tram, metropolitana, monorotaia |
| 7 | Ferrovia leggera e d'epoca | ferrovia a scartamento ridotto, ferrovia in miniatura, funicolare, ferrovia a cremagliera |
Qualsiasi cella che una strada o una ferrovia attraversa riceve la sua classe, quindi ogni cella ritorna come una linea ininterrotta indipendentemente da come viene attraversata. Dove due condividono una cella, viene mantenuto il pericolo peggiore, in questo ordine, il peggiore per primo: 1 motorway and trunk, 5 heavy railway, 2 A road, 6 medium railway, 3 B road, 7 light and heritage railway, 4 tertiary road. Anything in a tunnel is left out, and so are disused railways; the minor roads and lanes between villages and farms (OpenStreetMap's unclassified roads) count with tertiary as class 4, while town side streets, driveways, car parks and farm tracks are never included. Heavy railway is every standard gauge line, so standard gauge heritage lines count as heavy.
The cells
The grid is the Inland Water API's: cells of 1/12000 of a degree each way (about 9.3 m north to south), row 0 the north edge and column 0 the west edge, righe che vanno a sud e colonne a est. Ogni cella è tre bit, la sua classe, le celle disposte una dopo l'altra lungo la riga con la prima cella nei bit più significativi del primo byte, quindi otto celle riempiono esattamente tre byte. Ogni riga è riempita a un numero intero di byte, quindi riga j inizia al byte j * row_bytes.
Ground not yet in the database is 0 as well; the JSON answer's coverage_pct indica quanto del quadrato il database contiene, road_pct quanto di essa è una strada o una ferrovia, e class_pct quanto tempo ogni classe viene conservato.
Dimensioni
Alle latitudini del Regno Unito (54°N), prima della compressione:
| Quadrato | Celle | File |
|---|---|---|
| 1 km | 108 × 186 | 7,4 KB |
| 3 km | 324 × 556 | 66 KB |
| 5 km | 540 × 926 | 183 KB |
| 10 km | 1.078 × 1.850 | 731 KB |
| 20 km | 2.156 × 3.700 | 2,9 MB |
| 30 km | 3.234 × 5.550 | 6,4 MB |
Strade e ferrovie occupano una minuscola frazione del terreno, quindi la compressione le riduce a una piccola parte della loro dimensione originale.
Il file binario
Stesso intestazione di 32 byte dei file di acqua e chioma arborea, con versione 2 e tre bit per cella.
| Byte | Tipo | Valore |
|---|---|---|
| 0 | char[4] | ACRD |
| 4 | uint8 | Versione, 2 |
| 5 | uint8 | Bit per cella, 3 |
| 6 | uint16 | Celle per grado, 12000 |
| 8 | int32 | Bordo nord in celle: sua latitudine × 12000 |
| 12 | int32 | Bordo ovest in celle: la sua longitudine × 12000 |
| 16 | uint32 | Righe |
| 20 | uint32 | Colonne |
| 24 | uint32 | Byte per riga |
| 28 | uint32 | 0, riservato |
Una posizione viene mappata alla sua cella esattamente: riga north_edge - 1 - floor(lat * 12000), colonna floor(lon * 12000) - west_edge.
Esempi
https://www.altimetercloud.com/api/roads/?lat=54.35&lon=-2.95&size_km=3
https://www.altimetercloud.com/api/roads/?lat=54.35&lon=-2.95&size_km=5&classes=1,2,5&format=bin&compress=zlib
https://www.altimetercloud.com/api/roads/?lat=54.35&lon=-2.95&size_km=10&format=bin&compress=lzma&download=1
Lettura delle celle
Su un dispositivo
L'intestazione ha la stessa struttura del file water (vedi Inland Water API); cells sono i byte subito dopo. I tre bit di una cella possono straddle due byte, quindi leggili come una posizione di bit lungo la riga:
// C: the class at a position, 0 to 7, or -1 outside the square
int roadClassAt(const GridHeader *h, const uint8_t *cells, double lat, double lon) {
int32_t j = h->north_edge - 1 - (int32_t)floor(lat * h->cells_per_deg);
int32_t i = (int32_t)floor(lon * h->cells_per_deg) - h->west_edge;
if (j < 0 || i < 0 || j >= (int32_t)h->rows || i >= (int32_t)h->cols) return -1;
const uint8_t *row = cells + (uint32_t)j * h->row_bytes;
uint32_t bit = (uint32_t)i * 3; // first bit of the cell along the row
uint32_t two = ((uint32_t)row[bit >> 3] << 8)
| ((bit >> 3) + 1 < h->row_bytes ? row[(bit >> 3) + 1] : 0);
return (two >> (13 - (bit & 7))) & 7; // the 3 bits, wherever they start
}
Su un computer
# Python
import requests, struct, zlib, numpy as np
r = requests.get('https://www.altimetercloud.com/api/roads/',
params={'lat': 54.35, 'lon': -2.95, 'size_km': 3, 'format': 'bin', 'compress': 'zlib'})
f = zlib.decompress(r.content) # or lzma.decompress(r.content, format=lzma.FORMAT_ALONE)
magic, ver, bits, cpd, north, west, rows, cols, rb, _ = struct.unpack('<4sBBHiiIIII', f[:32])
b = np.unpackbits(np.frombuffer(f[32:], np.uint8).reshape(rows, rb), axis=1)[:, :cols * 3]
classes = (b[:, 0::3] << 2) | (b[:, 1::3] << 1) | b[:, 2::3] # rows x cols, 0 to 7
La risposta JSON
{
"success": true,
"lat", "lon", "size_km", "bits", bits is 3
"rows", "cols", "cells", "row_bytes", the grid, as above
"cells_per_degree", "north_edge_cell", "west_edge_cell",
"north", "south", "west", "east", the square's edges, degrees
"cell_deg", "cell_m_north_south", "cell_m_east_west",
"road_pct", cells with any road or railway kept
"class_pct": { "1": ..., "5": ... }, each class kept
"classes": { "1": "motorway and trunk", ... },
"kept": [1, 2, 3, 4, 5, 6, 7], the classes asked for
"coverage_pct", cells the database holds
"meaning", "order", "compress", "bytes",
"data_b64", the rows, row 0 first, compressed if asked
"file_name", "seconds",
"credits": { "roads", "source", "licence", "full" }
}
Errors
| Code | Meaning |
|---|---|
412 | A parameter is missing or not valid, the square is more than 30 km, JSON was asked for over 10 km, or classes= is not a list of 1 to 7 |
413 | The square has too many cells, which only happens very close to the poles |
429 | Troppi richieste dal tuo indirizzo, o una ancora in elaborazione |
501 | La compressione richiesta non è disponibile al momento |
Prova
Il Main Roads and Railways Map has a download panel: move the map so the cross sits on your launch site, choose the size and compression, and it saves the file from this API.
Road and railway data credits
Contains OpenStreetMap data © OpenStreetMap contributors, available under the Open Database Licence (ODbL), through the regional extracts published by Geofabrik. The main roads and railways are reduced here to a class a cell, which changes them: this is not the original data.
Licence of this data. Because it contains OpenStreetMap data, the data this API gives out is made available under the Open Database License (ODbL) 1.0. You may use it freely, commercially too, as long as you credit it as above and share any database you make from it under the same licence.
Crediti ad AltimeterCloud
Gratuito. Se usi this API, or anything made from the answers, in a commercial product or service, credit AltimeterCloud with a link to www.altimetercloud.com nel punto di utilizzo: sullo schermo, pagina o stampa dove appaiono i dati, ad esempio “Data from AltimeterCloud.com”. Tutti i crediti che le fonti dei dati richiedono, elencati su questa pagina, si applicano anche.



















