主要道路和铁路 API

访问与限制Public, no key needed · Heavy▾

对所有人开放。来自您的个人资料的免费 API 密钥可提高限制:将其发送到 X-API-Key header, or as 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位类别 每个地址每小时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 (默认值,适用于最大 10 km 的正方形)或 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 km540 × 926183 KB
10 km1,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
5uint8每个单元格比特数,3
6uint16单位度数的单元格数,12000
8int32北边界(单位:单元格):纬度 × 12000
12int32西边界(单位:单元格):经度 × 12000
16uint32行
20uint32列
24uint32每行字节数
28uint320,保留

A position maps to its cell exactly: row 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

Het lezen van de cellen

在设备上

标头的结构与水文件相同(请参阅 内陆水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”。此页面上列出的数据自身来源要求的任何署名也适用。