Main Roads & Railways API
Toegang & limietenPublic, no key needed · Heavy▾
Mijn profielpagina openen X-API-Key header, of als api_key= in het adres.
| 5 minuten | Uur | Dag | |
|---|---|---|---|
| Zonder sleutel | 20 | 120 | 500 |
| Met een sleutel | 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.
Log in om een gratis sleutel op je profielpagina aan te maken.
Elk antwoord bevat X-RateLimit-Remaining en X-RateLimit-Reset. Over een limiet, het antwoord is fout 429 met retry_after in seconden. Geweigerde verzoeken tellen niet mee.
Waar de grote wegen en spoorlijnen liggen over een vierkant rond een punt, en wat elk is: elke cel van ongeveer 10 meter komt terug als een van zeven klassen, van snelwegen tot erfgoedspoorlijnen, dezelfde gegevens als Kaart Hoofd-wegen en Spoorlijnen tekeningen. Het is bedoeld als een landingshaardlaag naast de Binnenwateren-API, zodat een landingstool een grotere marge van een snelweg kan houden dan van een rustige weg: vraag het aan als JSON voor een webpagina of script, of als een klein binair bestand dat een vliegcomputer of grondstation mee kan nemen.
lat lon size_kmParameters
| Parameter | Betekenis |
|---|---|
lat, lon | Het midden van het vierkant, decimale graden (lng ook geaccepteerd) |
size_km | De zijde van het vierkant in km, meer dan 0 en tot 30. Indien weggelaten, 1. Vierkanten boven 10 km worden geleverd als format=bin alleen. |
format | Optioneel. json (de standaardwaarde, voor vierkanten tot 10 km) of bin: een 32-byte kop en de cellen, als een bestand, voor elke grootte. |
compress | Optioneel. none (de standaard), zlib of lzma, zoals op de Binnenwateren-API. |
classes | Optioneel. De klassen om te behouden, als een lijst zoals 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 | Zwaar spoor | rail |
| 6 | Middelbare spoorweg | light rail, tram, subway, monorail |
| 7 | Licht- en erfgoedrailway | smalspoor, miniatuurrailway, funiculaire, tandradbaan |
Elke cel die een weg of spoorlijn raakt, krijgt zijn klasse, dus elk komt terug als een ononderbroken lijn van cellen hoe het ook loopt. Waar twee een cel delen, wordt het ergere gevaar bewaard, in deze volgorde, eerst het ergste: 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, rijen naar het zuiden en kolommen naar het oosten. Elke cel is drie bits, zijn klasse, de cellen achter elkaar langs de rij met de eerste cel in de hoogste bits van de eerste byte, dus acht cellen vullen precies drie bytes. Elke rij wordt opgevuld tot een geheel aantal bytes, dus rij j begint bij byte j * row_bytes.
Ground not yet in the database is 0 as well; the JSON answer's coverage_pct zegt hoeveel van het vierkant de database bevat, road_pct hoeveel daarvan een weg of spoorweg is, en class_pct hoeveel van elke klasse wordt behouden.
Maten
Bij UK-breedtegraden (54°N), voor compressie:
| Vierkant | Cellen | Bestand |
|---|---|---|
| 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 |
Wegen en spoorlijnen beslaan een minuscuul deel van de grond, dus compressie reduceert deze tot een fractie van hun ongecomprimeerde grootte.
Het binaire bestand
Dezelfde 32-byte header als de water- en boomkroonbestanden, met versie 2 en drie bits per cel.
| Byte | Type | Waarde |
|---|---|---|
| 0 | char[4] | ACRD |
| 4 | uint8 | Versie, 2 |
| 5 | uint8 | Bits per cel, 3 |
| 6 | uint16 | Cellen per graad, 12000 |
| 8 | int32 | Noord rand in cellen: zijn breedtegraad × 12000 |
| 12 | int32 | West rand in cellen: zijn lengtegraad × 12000 |
| 16 | uint32 | Rijen |
| 20 | uint32 | Kolommen |
| 24 | uint32 | Bytes per rij |
| 28 | uint32 | 0, gereserveerd |
Een positie komt exact overeen met zijn cel: rij north_edge - 1 - floor(lat * 12000), kolom floor(lon * 12000) - west_edge.
Voorbeelden
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
De cellen lezen
Op een apparaat
De header heeft dezelfde structuur als het waterbestand (zie het Binnenwateren-API); cells is de bytes meteen erna. De drie bits van een cel kunnen twee bytes omspannen, dus lees ze als een bitpositie langs de rij:
// 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
}
Op een 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
Het JSON-antwoord
{
"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 | Te veel aanvragen van uw adres, of er wordt nog een beantwoord |
501 | De aangevraagde compressie is nu niet beschikbaar |
Probeer het
De 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.
Altimeter Cloud erkennen
Gratis te gebruiken. Als u this API, or anything made from the answers, in a commercial product or service, credit AltimeterCloud with a link to www.altimetercloud.com op het punt van gebruik: op het scherm, pagina of afdruk waar de gegevens verschijnen, bijvoorbeeld “Data from AltimeterCloud.com”. Alle credits die de eigen bronnen van de gegevens vragen, vermeld op deze pagina, zijn ook van toepassing.



















