واجهة برمجة تطبيقات الطرق الرئيسية والسكك الحديدية

الوصول والحدودPublic, no key needed · Heavy▾

مفتوح للجميع. مفتاح API مجاني من ملفك الشخصي يرفع الحدود: أرسله في X-API-Key رأس، أو كـ api_key= في العنوان.

5 دقائقساعةيوم
بدون مفتاح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 أمتار تعود كواحدة من سبع فئات، من الطرق السريعة إلى السكك الحديدية التراثية، نفس البيانات خريطة الطرق الرئيسية والسكك الحديدية يرسم. المقصود به أن يكون طبقة خطر هبوط بجانب Inland Water 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 (الافتراضي، للمربعات حتى 10 كم) أو bin: رأس 32 بايت والخلايا، كملف، بأي حجم.
compressاختياري. none (الافتراضي), zlib أو lzma, كما على Inland Water 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 كيلوبايت
3 كم324 × 55666 كيلوبايت
5 كم540 × 926183 كيلوبايت
10 كم1,078 × 1,850731 KB
20 كم2,156 × 3,7002.9 MB
30 كم3,234 × 5,5506.4 MB

الطرق والسكك الحديدية تغطي جزءًا صغيرًا من الأرض، لذا يقلل الضغط هذه إلى جزء صغير من حجمها الخام.

الملف الثنائي

رأس 32 بايت نفسه مثل ملفات الماء والمظلة الشجرية، مع الإصدار 2 وثلاث بتات خلية.

بايتاكتبقيمة
0char[4]ACRD
4uint8الإصدار، 2
5uint8بت لكل خلية، 3
6uint16خلايا لكل درجة، 12000
8int32حافة الشمال بالخلايا: خطها × 12000
12int32الحافة الغربية بالخلايا: خط طولها × 12000
16uint32الصفوف
20uint32الأعمدة
24uint32بايتات لكل صف
28uint320، محجوز

يتم تعيين الموضع إلى خليته بالضبط: صف north_edge - 1 - floor(lat * 12000), عمود floor(lon * 12000) - west_edge.

أمثلة

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

قراءة الخلايا

على جهاز

الرأس له نفس هيكل ملف الماء (انظر إلى Inland Water 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.

إعادة أفضال Altimeter Cloud

مجاني الاستخدام. إذا كنت تستخدم 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”. Any credits the data's own sources ask for, listed on this page, apply as well.