Inland Water API

الوصول والحدود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 كم مربع فئات 2-bit 60 طلباً في الساعة لكل عنوان

حيث تكون المياه فوق مربع حول نقطة، وما نوعها: كل خلية بحوالي 10 أمتار تعود باعتبارها مياه عامة (بحيرات وخزانات وأحواض وأنهار وقنوات والبحر على الساحل)، أو جدول أو بيك، أو قناة أو صرف، أو جاف، نفس البيانات خريطة المياه الداخلية الرسومات. اطلبها كـ JSON لصفحة ويب أو نص برمجي، أو كملف ثنائي صغير يمكن لجهاز كمبيوتر الرحلة أو محطة الأرض حمله، بحيث يمكن دمج مياه موقع الإطلاق في firmware بدلاً من جلبها في اليوم.

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

المعاملات

معاملمعنى
lat, lonمنتصف المربع، الدرجات العشرية (lng مقبول أيضًا)
size_kmجانب المربع بالكيلومتر، أكثر من 0 وحتى 30. إذا تم حذفه، 1. المربعات التي تزيد عن 10 كم تأتي كـ format=bin فقط.
formatاختياري. json (الافتراضي، للمربعات حتى 10 كم): الخلايا بصيغة base64 داخل إجابة JSON مع كل شيء مطلوب لقراءتها. bin: رأس 32 بايت والخلايا، كملف، بأي حجم.
compressاختياري. none (الافتراضي), zlib أو lzma. مع format=bin the whole file is compressed; with json الخلايا قبل base64. lzma هو LZMA-alone (.lzma) مع قاموس 64 كيلوبايت، تماماً كما هو Tree Canopy 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 كيلوبايت
5 كم540 × 926122 كيلوبايت
10 كم1,078 × 1,850487 KB
20 كم2,156 × 3,7001.9 MB
30 كم3,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
}

المياه بالقرب مني

للهبوط، امش في الخلايا التي تقع منتصفاتها ضمن نطاق نصف قطره بالمتر من حجم الخلية: 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() من SDK LZMA، وعلى ESP32 compress=zlib لا يحتاج إلى أي شيء إضافي، لأن miniz tinfl في ROM الخاص به. انظر فك الضغط على جهاز تحكم دقيق على صفحة Tree Canopy.

على جهاز كمبيوتر

# 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”. Any credits the data's own sources ask for, listed on this page, apply as well.