Inland Water API
Acces și limitePublic, no key needed · Heavy▾
Deschis pentru toți. O cheie API gratuită din profilul dvs. ridică limitele: trimiteti-o în X-API-Key antet, sau ca api_key= pod adresem.
| 5 minute | Oră | Ziua | |
|---|---|---|---|
| Fără cheie | 20 | 120 | 500 |
| Cu o cheie | 60 | 400 | 2,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.
Conectați-vă pentru a crea o cheie gratuită pe pagina profilului dvs.
Fiecare răspuns poartă X-RateLimit-Remaining și X-RateLimit-Reset. Peste o limită, răspunsul este eroare 429 cu retry_after în secunde. Cererile refuzate nu se numără.
Unde apa se află peste un pătrat în jurul unui punct și ce fel: fiecare celulă de aproximativ 10 metri revine ca apă generală (lacuri, rezervoare, iazuri, râuri, canale și marea de-a lungul coastei), un pârâu, o șanț sau dren, sau uscat, aceleași date ca Hartă apelor interioare desenează. Solicitați-o sub forma JSON pentru o pagină web sau script, sau ca fișier binar mic pe care un calculator de zbor sau o stație de sol îl pot purta, pentru ca apa de lansare a unui sit să poată fi încorporată în firmware în loc să fie preluată în ziua lansării.
lat lon size_kmParametri
| Parametru | Semnificație |
|---|---|
lat, lon | Centrul pătratului, grade zecimale (lng de asemenea acceptat) |
size_km | Latura pătratului în km, mai mult de 0 și până la 30. Lăsat afară, 1. Pătrate peste 10 km sunt format=bin doar. |
format | Opțional. json (implicit, pentru pătrate până la 10 km): celulele ca base64 în răspunsul JSON cu tot ce este necesar pentru a le citi. bin: un antet de 32 de octeți și celulele, ca fișier, pentru orice dimensiune. |
compress | Opțional. none (valoarea implicită), zlib sau lzma. Cu format=bin the whole file is compressed; with json celulele sunt, înainte de base64. lzma este LZMA-alone (.lzma) cu un dicționar de 64 KB, exact cum API Crown Canopy o dă. |
classes | Opțional. Clasele de păstrat, sub formă de listă, cum ar fi 1,2; every other class comes back as 0. Left out, all three. |
download | Opțional. 1 face o aplicatie sa salveze un format=bin raspunde ca un fisier, numit dupa patrat. |
The classes
| Class | What | From |
|---|---|---|
| 0 | Dry | |
| 1 | General water | ESA 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 |
| 2 | Streams and becks | OpenStreetMap waterway=stream |
| 3 | Ditches and drains | OpenStreetMap 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. Rândul 0 este marginea nordică și coloana 0 marginea vestică; rows run south and columns east. Each cell is two bits, its class, celulele aliniate capă la capă de-a lungul rândului, cu prima celulă în biții cei mai semnificativi, deci patru celule ocupă fiecare octetFiecare rând începe pe un octet întreg, deci rând j începe la byte j * row_bytes.
Ground not yet in the database is 0 as well; the JSON answer's coverage_pct spune cât de mult din pătrat baza de date deține, water_pct cât de multă apă din clasele păstrate, și class_pct cât costă fiecare clasă. Afară pe mare, dincolo de plăcile WorldCover, nu sunt deloc date despre apă: marea deschisă vine din teren, pământ la sau sub 0 m.
Dimensiuni
La latitudinile Regatului Unit (54°N), înainte de compresie:
| Pătrat | Celule | Fișier |
|---|---|---|
| 1 km | 108 × 186 | 5.0 KB |
| 3 km | 324 × 556 | 44 KB |
| 5 km | 540 × 926 | 122 KB |
| 10 km | 1.078 × 1.850 | 487 KB |
| 20 km | 2.156 × 3.700 | 1,9 MB |
| 30 km | 3,234 × 5,550 | 4,3 MB |
Cel mai mult teren este uscat, deci compresia le ia pe acestea o cale lungă: un pătrat cu câteva lacuri și pâraie din el de obicei se pliază la o mică fracțiune din dimensiunea sa brută, și lzma este cel mai mic.
Fișierul binar
Cu 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.
| Byte | Tip | Valoare |
|---|---|---|
| 0 | char[4] | ACWT |
| 4 | uint8 | Versiune, 2 |
| 5 | uint8 | Biți pe celulă, 2 |
| 6 | uint16 | Zellen pro Grad, 12000 |
| 8 | int32 | Marginea nordică în celule: latitudine × 12000 |
| 12 | int32 | Marginea de vest în celule: longitudinea sa × 12000 |
| 16 | uint32 | Rânduri |
| 20 | uint32 | Coloane |
| 24 | uint32 | Octeți pe rând |
| 28 | uint32 | 0, rezervat |
Marginile sunt numere întregi de celule, deci o poziție se mapează exact la celula ei: rând north_edge - 1 - floor(lat * 12000), coloană floor(lon * 12000) - west_edge.
Exemple
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
Răspunsul 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
}
Apă lângă mine
Pentru aterizare, parcurgeți celulele ale căror mijloace se află într-o rază, lucrând în metri din dimensiunea celulei: 111320 / 12000 m de la nord la sud și asta ori cosinusul latitudinii vest la est. Cea mai rea clasă din cerc, ponderea celulelor care sunt apă și cea mai mică distanță până la fiecare clasă vin dintr-o singură trecere.
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; }
}
Despachetare pe un microcontroller
Compresia este aceeași ca a fișierelor copertei de copaci: compress=lzma se despachetează cu LzmaDecode() din SDK-ul LZMA și pe ESP32 compress=zlib nu necesită nimic suplimentar, aşa cum miniz-ul tinfl se află în ROM-ul său. Vezi Despachetare pe un microcontroller pe pagina Tree Canopy.
Pe un computer
# 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
Erori
Erorile sunt returnate ca JSON cu "success": false, un cod și un mesaj.
| Cod | Semnificație |
|---|---|
412 | A 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 | Pătratul are prea multe celule, ceea ce se întâmplă doar foarte aproape de poli |
429 | Prea multe cereri de la adresa dvs., sau una în curs de procesare |
501 | Compresia cerută nu este disponibilă acum |
Încearcă
The 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.
Creditare AltimeterCloud
Gratuit. Dacă utilizați this API, or anything made from the answers, in a commercial product or service, credit AltimeterCloud with a link to www.altimetercloud.com în punctul de utilizare: pe ecran, pagină sau tipar unde apar datele, de exemplu “Data from AltimeterCloud.com”. Orice credite pe care sursele proprii ale datelor le cer, listate pe această pagină, se aplică și ele.



















