Main Roads & Railways API

גישה והגבלותPublic, no key needed · Heavy▾

פתוח לכולם. מפתח API חינמי מהפרופיל שלך מגביל את הגבולות: שלח אותו ב- X-API-Key כותרת, או כ api_key= בכתובת.

5 דקותHourיום
ללא מפתח20120500
עם מפתח604002,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.

היכנסו כדי ליצור מפתח בחינם בעמוד הפרופיל שלכם.

כל תשובה נושאת X-RateLimit-Remaining ו X-RateLimit-Reset. מעל לגבול, התשובה היא שגיאה 429 עם retry_after בשניות. בקשות שנדחו אינן סופרות.

GET אין צורך בחיתום קובץ JSON או בינארי עד 30 קמ"ר שיעורים של 3-bit 60 בקשות לשעה לכל כתובת

איפה הכבישים הראשיים והרכבות על ריבוע סביב נקודה, ומה כל אחד: כל תא של כ-10 מטרים חוזר כאחד משבע שיעורים, מכבישים מהירים לרכבות מורשת, אותן נתונים ה מפת כבישים ורכבת ראשיים מצייר. זה מיועד כשכבת סיכון נחיתה לצד API למים פנימיים, כך שכלי נחיתה יכול להחזיק שוליים רחבים יותר מאוטוסטרדה מאשר מדרך שקטה: בקש את זה כ-JSON לעמוד אינטרנט או סקריפט, או כקובץ בינארי קטן שמחשב טיסה או תחנת קרקע יכול לשאת.

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

פרמטרים

פרמטרמשמעות
lat, lonאמצע הריבוע, מעלות עשרוניות (lng מקובל גם)
size_kmהצלע של הריבוע בקילומטרים, יותר מ-0 ועד 30. אם הושמט, 1. ריבועים מעל 10 ק"מ מגיעים כ format=bin בלבד.
formatאופציונלי. json (domyślnie dla kwadratów do 10 km) lub bin: כותרת בת 32 בתים והתאים, כקובץ, בכל גודל.
compressאופציונלי. none (ברירת המחדל), zlib או lzma, כמו ב API למים פנימיים.
classesאופציונלי. המחלקות לשמור, כרשימה כגון 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)
5רכבת כבדהמנחת
6מסילה בינוניתמסילה קלה, טרם, רכבת תחתית, מונוריל
7רכבת קלה ומורשתמסילה צרה, רכבת זעירה, פוניקולייר, רכבת הילוכים

כל תא שהדרך או הרכבת חוצה בכלל מקבל את הסיווג שלו, כך שכל אחד חוזר כקו תאים ללא הפסק כיצד הוא רץ. כאשר שניים חולקים תא, הסכנה הגרועה יותר נשמרת, בסדר זה, הגרוע ביותר ראשון: 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, שורות רצות דרומה וטורים מזרחה. כל תא הוא שלוש ביטים, הסיווג שלו, התאים מונחים בשורה עם התא הראשון בביטים הגבוהים ביותר של הבית הראשון, כך שמונה תאים מלאים בדיוק שלוש בתים. כל שורה מרופדת למספר שלם של בתים, כך ששורה j מתחיל בבית j * row_bytes.

Ground not yet in the database is 0 as well; the JSON answer's coverage_pct מציג כמה מהריבוע מכיל מסד הנתונים, road_pct כמה מזה היא כל כביש או מסילת רכבת, ו class_pct כמה מכל מחלקה נשמרת.

גדלים

בקווי הרוחב של בריטניה (54°N), לפני דחיסה:

מרובעתאיםקובץ
1 ק"מ108 × 1867.4 KB
3 קמ״ש324 × 55666 KB
5 ק"מ540 × 926183 KB
10 ק"מ1,078 × 1,850731 KB
20 ק״מ2,156 × 3,7002.9 MB
30 km3,234 × 5,5506.4 MB

כבישים ורכבות מכסים חלק זעום של הקרקע, כך שדחיסה מקטינה אלה לשבר קטן מגודלם הגולמי.

קובץ בינארי

אותו כותרת של 32 בתים כמו בקבצי חסימת המים ולעלווה עצים, עם גרסה 2 ושלוש ביטים לתא.

בתיםסוגערך
0char[4]ACRD
4uint8גרסה, 2
5uint8Bits לתא, 3
6uint16תאים לכל מעלה, 12000
8int32קצה צפון בתאים: הקו רוחב שלו × 12000
12int32Zachodnia krawędź w komórkach: jej długość geograficzna × 12000
16uint32שורות
20uint32עמודות
24uint32בתים לכל שורה
28uint320, vyhrazeno

מיקום מפות לתא שלו בדיוק: שורה north_edge - 1 - floor(lat * 12000), עמודה floor(lon * 12000) - west_edge.

Przykłady

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

קריאת התאים

Egy eszközön

הכותרת היא אותה מבנה כמו של קובץ המים (ראו את API למים פנימיים); cells הוא הבתים ישר אחרי זה. שלוש הביטים של תא יכולים להחזיק שני בתים, אז קרא אותם כמיקום ביט לאורך השורה:

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

על מחשב

# 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

התשובה 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

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
429יותר מדי בקשות מכתובתך, או אחת עדיין מחכה לתשובה
501הדחיסה המבוקשת אינה זמינה כעת

נסה זאת

ה- 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.

קרדיט AltimeterCloud

חינם לשימוש. אם אתה משתמש this API, or anything made from the answers, in a commercial product or service, credit AltimeterCloud with a link to www.altimetercloud.com בנקודת השימוש: על המסך, בעמוד או בהדפסה שבו הנתונים מופיעים, לדוגמה “Data from AltimeterCloud.com”. כל קרדיטים שמקורות הנתונים שלעצמם מבקשים, מופעלים בעמוד זה, חלים גם כן.