Hauptstraßen & Bahnstrecken API

Zugang & LimitsPublic, no key needed · Heavy▾

Offen für alle. Ein kostenloser API-Schlüssel aus Ihrem Profil erhöht die Limits: Senden Sie ihn in einem X-API-Key Kopfzeile oder als api_key= in der Adresse.

5 MinutenStundeTag
Ohne Schlüssel20120500
Mit einem Schlüssel604002,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.

Melde dich an, um einen kostenlosen Schlüssel auf deiner Profilseite zu erstellen.

Jede Antwort trägt X-RateLimit-Remaining und X-RateLimit-Reset. Über einem Limit ist die Antwort Fehler 429 mit retry_after in Sekunden. Abgelehnte Anfragen zählen nicht.

GET Kein Schlüssel erforderlich JSON- oder Binärdatei Bis zu 30 km Quadrat 3-Bit-Klassen 60 Anfragen pro Stunde pro Adresse

Wo die Hauptstraßen und Eisenbahnen über einem Quadrat um einen Punkt liegen, und was jede ist: jede Zelle von etwa 10 Metern wird als eine von sieben Klassen zurückgegeben, von Autobahnen bis zu Museumseisenbahnen, die gleichen Daten wie Karte mit Hauptstraßen und Eisenbahnen Zeichnungen. Sie dient als Landegefahrenschicht neben der Inland Water API, damit ein Landungswerkzeug einen größeren Abstand von einer Autobahn als von einer ruhigen Straße halten kann: als JSON für eine Webseite oder ein Skript anfordern oder als kleine Binärdatei, die ein Flugcomputer oder eine Bodenstation mitführen kann.

GEThttps://www.altimetercloud.com/api/roads/lat lon size_km

Parameter

ParameterBedeutung
lat, lonDie Mitte des Quadrats, dezimal Grad (lng auch akzeptiert)
size_kmDie Seitenlänge des Quadrats in km, mehr als 0 und bis zu 30. Wenn nicht angegeben, 1. Quadrate über 10 km werden als format=bin nur.
formatOptional. json (Standard für Quadrate bis 10 km) oder bin: ein 32-Byte-Header und die Zellen als Datei beliebiger Größe.
compressOptional. none (der Standard), zlib oder lzma, wie auf dem Inland Water API.
classesOptional. Die zu behaltenden Klassen als Liste wie 1,2,5; every other class comes back as 0. Left out, all seven.
downloadOptional. 1 makes a browser save a format=bin answer as a file, named for the square.

The classes

ClassWhatOpenStreetMap types
0Nothing
1Motorway and trunk roadmotorway, trunk, and their slip roads
2A roadprimary and its slip roads
3B roadsecondary and its slip roads
4Tertiary and minor roadtertiary and its slip roads; unclassified (the public minor roads and lanes between villages and farms)
5Schwere EisenbahnFührungsschiene
6Mittlere EisenbahnStraßenbahn, U-Bahn, Einschienenbahn
7Leichte Bahn und SchmalspurbahnSchmalspurbahn, Feldbahn, Zahnradbahn, Zahnstangenbahn

Jede Zelle, die eine Straße oder Eisenbahn überhaupt kreuzt, erhält ihre Klasse, daher wird jede als ununterbrochene Zellenreihe zurückgegeben, egal wie sie verläuft. Wo zwei sich eine Zelle teilen, wird die größere Gefahr behalten, in dieser Reihenfolge, Worst first: 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, Reihen in Südrichtung und Spalten in Ostrichtung. Jede Zelle ist drei Bits, ihre Klasse, die Zellen nacheinander entlang der Reihe angeordnet, wobei die erste Zelle in den höchstwertigen Bits des ersten Bytes liegt, daher acht Zellen füllen genau drei Bytes. Jede Reihe wird auf eine ganze Anzahl von Bytes aufgefüllt, daher Reihe j beginnt bei Byte j * row_bytes.

Ground not yet in the database is 0 as well; the JSON answer's coverage_pct gibt an, wie viel des Quadrats die Datenbank enthält., road_pct wie viel davon eine Straße oder Eisenbahn ist, und class_pct wie viel von jeder Klasse behalten wird.

Größen

Bei britischen Breitengraden (54°N), vor der Komprimierung:

QuadratZellenDatei
1 km108 × 1867,4 KB
3 km324 × 55666 KB
5 km540 × 926183 KB
10 km1.078 × 1.850731 KB
20 km2.156 × 3.7002,9 MB
30 km3.234 × 5.5506,4 MB

Straßen und Eisenbahnen nehmen eine winzige Fläche ein, daher wird die Komprimierung diese auf einen kleinen Bruchteil ihrer Rohgröße reduziert.

Die binäre Datei

Der gleiche 32-Byte-Header wie bei den Wasser- und Baumkronendateien, mit Version 2 und drei Bits pro Zelle.

ByteTypWert
0char[4]ACRD
4uint8Version 2
5uint8Bits pro Zelle: 3
6uint16Zellen pro Grad: 12000
8int32Nordkante in Zellen: ihre Breite × 12000
12int32Westkante in Zellen: ihre Länge × 12000
16uint32Zeilen
20uint32Spalten
24uint32Bytes pro Zeile
28uint320, reserviert

Eine Position wird ihrer Zelle genau zugeordnet: Reihe north_edge - 1 - floor(lat * 12000), Spalte floor(lon * 12000) - west_edge.

Beispiele

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

Lesen der Zellen

Auf einem Gerät

Der Header hat die gleiche Struktur wie die des Wasser-Dateien (siehe die Inland Water API); cells ist das Byte direkt danach. Die drei Bits einer Zelle können sich über zwei Bytes erstrecken, daher müssen sie als Bitposition entlang der Reihe gelesen werden:

// 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
}

Auf einem 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

Die JSON-Antwort

{
  "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

CodeMeaning
412A 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
413The square has too many cells, which only happens very close to the poles
429Zu viele Anfragen von Ihrer Adresse, oder eine wird noch bearbeitet
501Die angeforderte Komprimierung ist gerade nicht verfügbar

Probieren Sie es

Das 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 würdigen

Kostenlos zu nutzen. Falls Sie this API, or anything made from the answers, in a commercial product or service, credit AltimeterCloud with a link to www.altimetercloud.com am Ort der Verwendung: auf dem Bildschirm, in der Seite oder im Ausdruck, in dem die Daten angezeigt werden, beispielsweise “Data from AltimeterCloud.com”. Alle Quellenangaben, die die Datenquellen selbst anfordern, sind auf dieser Seite aufgeführt und gelten ebenfalls.