内陆水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公里方形 2位级别 每个地址每小时60个请求

在水覆盖点周围的正方形的地方,以及何种类型:大约 10 米的每个单元格都会返回为一般水体(湖泊、水库、池塘、河流、运河和沿海岸的海洋)、小溪或河流、沟渠或排水沟或干燥,与 内陆水域地图 绘制。要求它作为网页或脚本的 JSON,或作为飞行计算机或地面站可以携带的小型二进制文件,以便发射场的水可以内置到固件中,而不是在当天获取。

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

参数

参数含义
lat, lon正方形中心,十进制度数(lng 也被接受)
size_km正方形的边长(以公里为单位),大于 0 且最多 30。如果省略,则为 1。边长超过 10 公里的正方形作为 format=bin 仅限。
format可选。 json (默认值,适用于最大10 km的正方形):单元格作为base64在JSON答案中,包含读取它们所需的所有内容。 bin: 包含 32 字节标头和单元格的文件,适用于任何大小。
compress可选。 none (默认值), zlib 或 lzma。与 format=bin the whole file is compressed; with json 单元格在 base64 之前的情况。 lzma 是 LZMA-alone (.lzma)使用 64 KB 字典,完全相同 树冠 API 使其产生。
classes可选。要保留的类别,作为列表,例如 1,2; every other class comes back as 0. Left out, all three.
download可选。 1 使浏览器保存一个 format=bin 以命名的文件形式回答。

The classes

ClassWhatFrom
0Dry
1General waterESA WorldCover's permanent water; OpenStreetMap's lakes, ponds, reservoirs, marina basins and river areas; rivers and canals mapped as lines; the sea along the coast
2Streams and becksOpenStreetMap waterway=stream
3Ditches and drainsOpenStreetMap waterway=drain and ditch

Any cell with water in it at all takes its class, however little: a stream a metre wide comes back as an unbroken line of cells. That is meant for hazard checks, where a cell with any water in it is a place something can land wet. Where two classes meet in a cell the worse is kept, 1 over 2 over 3, so a stream running into a lake is part of the lake. Many ditches and drains are dry for much of the year, and streams and drains that pass through culverts may show as open where they are not; classes=1,2 leaves ditches and drains out.

The satellite part gives the same quality worldwide; the OpenStreetMap part fills in what the satellite cannot see, such as shaded rivers, crowded marinas and anything narrower than a cell, but only has what has been mapped. The satellite water is as it stood in 2021.

The cells

The grid is the water store's own, so nothing is resampled: each cell is exactly 1/12000 of a degree each way, about 9.3 m north to south and, at UK latitudes, about 5.5 m east to west. 第 0 行是北边缘,第 0 列是西边缘; rows run south and columns east. Each cell is 两位,其类别, 单元格沿行端对端排列,第一个单元格在最高位,所以 四个单元格填充每个字节。每行从整字节开始,因此行 j 从字节开始 j * row_bytes.

Ground not yet in the database is 0 as well; the JSON answer's coverage_pct 表示数据库保存了多少方形, water_pct 其中多少是保留的类的水,以及 class_pct 每个类别有多少。在海上,超出 WorldCover 瓷砖范围,根本没有水数据:开放海域来自地形,地面在 0 米或以下。

尺寸

在英国纬度 (54°N) 处,压缩前:

正方形单元格文件
1 公里108 × 1865.0 KB
3 公里324 × 55644 KB
5 km540 × 926122 KB
10 km1,078 × 1,850487 KB
20 公里2,156 × 3,7001.9 MB
30 km3,234 × 5,5504.3 MB

大部分地面干燥,所以压缩会将其压缩很远:一个有几个湖泊和小溪的正方形通常会压缩到其原始大小的一小部分,以及 lzma 是最小的。

二进制文件

带有 format=bin: a 32 byte header, little endian, then the rows, north first. It is the same layout as the tree canopy and roads files, so one reader handles all three; only the name, the version and the bits a cell differ.

字节类型值
0char[4]ACWT
4uint8版本 2
5uint8每个单元格比特数,2
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/water/?lat=54.35&lon=-2.95&size_km=3
https://www.altimetercloud.com/api/water/?lat=54.35&lon=-2.95&size_km=5&classes=1,2&format=bin&compress=zlib
https://www.altimetercloud.com/api/water/?lat=54.35&lon=-2.95&size_km=10&format=bin&compress=lzma&download=1

JSON答案

{
  "success": true,
  "lat", "lon", "size_km", "bits",           bits is 2
  "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",
  "water_pct",                               cells with water of the classes kept
  "class_pct": { "1": ..., "2": ... },       each class kept
  "classes": { "1": "general water", ... },
  "kept": [1, 2, 3],                         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": { "water", "source", "doi", "licence", "full" }
}

Reading the cells

On a device: what water is below me

Give a position and get the class of the cell it is in. The file sits in flash or on a card, and cells is the bytes straight after the 32 byte header. Use doubles for the position.

// C
typedef struct __attribute__((packed)) {
  char     magic[4];        // "ACWT" (roads "ACRD", trees "ACTR")
  uint8_t  version;         // 2
  uint8_t  bits;            // 2
  uint16_t cells_per_deg;   // 12000
  int32_t  north_edge;      // latitude of the north edge * 12000
  int32_t  west_edge;       // longitude of the west edge * 12000
  uint32_t rows, cols, row_bytes, reserved;
} GridHeader;

// the class at a position, 0 to 3, or -1 outside the square
int waterClassAt(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;
  uint8_t b = cells[(uint32_t)j * h->row_bytes + (i >> 2)];
  return (b >> (6 - 2 * (i & 3))) & 3;          // four cells a byte, first in the top bits
}

Water dichtbij

对于着陆,行走中点位于一个半径内的单元格,以单元格大小以米为单位工作: 111320 / 12000 米,从北到南,乘以纬度的余弦(从西到东)。圆圈中最差的类别、水的单元格比例和每个类别的最小距离都来自一次扫描。

double ch = 111320.0 / h->cells_per_deg, cw = ch * cos(lat * M_PI / 180.0);
int ny = (int)(radius_m / ch) + 1, nx = (int)(radius_m / cw) + 1, wet = 0, all = 0;
double nearest[4] = { -1, -1, -1, -1 };             // by class
for (int dy = -ny; dy <= ny; dy++)
  for (int dx = -nx; dx <= nx; dx++) {
    double d = sqrt((dx * cw) * (dx * cw) + (dy * ch) * (dy * ch));
    if (d > radius_m) continue;
    int c = waterClassAt(h, cells, lat + dy / (double)h->cells_per_deg, lon + dx / (double)h->cells_per_deg);
    if (c < 0) continue;
    all++;
    if (c) { wet++; if (nearest[c] < 0 || d < nearest[c]) nearest[c] = d; }
  }

在微控制器上解包

压缩与树冠文件的相同: compress=lzma 解包自 LzmaDecode() 来自 LZMA SDK 和 ESP32 compress=zlib 不需要任何额外的,因为 miniz 的 tinfl 在其 ROM 中。请参阅 在微控制器上解包 在树冠页面上。

在计算机上

# Python
import requests, struct, zlib, numpy as np
r = requests.get('https://www.altimetercloud.com/api/water/',
                 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 * 2]
water = (b[:, 0::2] << 1) | b[:, 1::2]      # rows x cols, 0 dry, 1 water, 2 stream, 3 ditch
lat_of_row = lambda j: (north - j - 0.5) / cpd
lon_of_col = lambda i: (west + i + 0.5) / cpd

错误

错误以 JSON 返回 "success": false, 代码和消息。

代码含义
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 3
413正方形有太多单元格,这仅在非常靠近极地时才会发生
429来自您的地址的请求太多,或者仍有一个在处理中
501所请求的压缩方式目前不可用

试一下

那 Inland Water 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.

Water data credits

© ESA WorldCover project 2021 / Contains modified Copernicus Sentinel data (2021) processed by ESA WorldCover consortium. ESA WorldCover 10 m 2021 v200, Zanaga, D. et al. 2022, doi:10.5281/zenodo.7254221, licensed under CC BY 4.0.

Contains OpenStreetMap data © OpenStreetMap contributors, available under the Open Database Licence (ODbL).

The two are combined here and reduced to a water class a cell, which changes them: this is not the original data of either.

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”。此页面上列出的数据自身来源要求的任何署名也适用。