game-dem-v2 / README.md
ycydev's picture
Add the dataset card
8999db9 verified
|
Raw History Blame Contribute Delete
11.2 kB
---
pretty_name: Global 90 m Terrain Packages
license: other
license_name: copernicus-dem
license_link: https://dataspace.copernicus.eu/
tags:
- dem
- elevation
- terrain
- heightmap
- copernicus
- geospatial
size_categories:
- 10K<n<100K
---
# Global 90 m terrain packages
Elevation for the Earth's land surface, cut into 1°×1° packages and stored so a
single tile can be read with one HTTP ranged request — no need to download a
package, let alone the dataset, to look at one place.
Derived from Copernicus GLO-90, reprojected to an equal-area grid at 90 m.
| | |
| --- | --- |
| Packages published | 26,475 |
| Cells in the grid | 64,800 (180 × 360) |
| Total size | ~8.6 GB |
| Files per package | 2 |
| Grid | EPSG:6933, 90 m sample spacing |
| Tile | 256 × 256 samples |
| Coverage | land only, up to ~83° N (where the source ends) |
Cells that are entirely ocean publish nothing at all, which is why 26,475 cells
carry the whole planet's land.
## Layout
```
coverage.json
packages/N046/E008/dataset.json
packages/N046/E008/terrain.dtrn
packages/S034/W059/dataset.json
packages/S034/W059/terrain.dtrn
...
```
A package id is its southwest corner: `N046/E008` is the cell from 46°N to 47°N
and 8°E to 9°E. Latitude is three digits, longitude is three digits, both zero
padded.
## Start with coverage.json
```json
{
"version": 1,
"gridVersion": "earth-v2-glo90",
"packages": ["N000/E006", "N000/E009", "..."]
}
```
A sorted list of every package that exists. A cell that is not listed has no
published terrain — it is ocean, or beyond the source's northern limit. Check
this before requesting a package rather than treating a 404 as an answer.
## Finding the package for a place
```js
const pad = (value) => String(Math.abs(value)).padStart(3, '0');
function packageId(latitude, longitude) {
const south = Math.floor(latitude);
const west = Math.floor(longitude);
return `${south >= 0 ? 'N' : 'S'}${pad(south)}/${west >= 0 ? 'E' : 'W'}${pad(west)}`;
}
packageId(46.8, 8.4); // "N046/E008"
```
## dataset.json
The package index. It carries the tile table and everything needed to place the
samples; the bundle beside it carries only bytes.
| Field | What it holds |
| --- | --- |
| `tileFormat` | `version` 3, `codec` `deflate-raw`, `tileSize` 256, `predictor` 4, `compressionLevel` 6, `heightUnitMeters` 1 |
| `tileGrid` | `originEasting`, `originNorthing`, `sampleSpacingMeters` 90, `tileSize`, and `coordinateSystem` — `x: easting`, `z: southward-northing` |
| `bundle` | `path`, `bytes`, `tileCount`, `checksum` (SHA-256), `headerBytes` |
| `tiles` | one entry per tile that has land: `tileX`, `tileZ`, `width`, `height`, `offset`, `length`, `bytes`, `checksum`, `status` |
| `tileIndex` | every tile in the package, including those with no land, so the extent is known without the frames |
| `gameTransform` | the height mapping described below |
| `sourceBounds` | the cell's bounds in the source's terms |
| `attribution` | the notice reproduced at the bottom of this card |
`offset` and `length` are the tile's position in `terrain.dtrn`, in bytes,
counted from the start of the file — the two numbers a ranged request needs. The
first tile therefore starts at 16, immediately after the bundle header.
`tileX` and `tileZ` are indices on the global grid, not within the package, so
they are frequently negative and never start at zero. Two tiles from different
packages never share a pair.
## terrain.dtrn — the bundle
A 16-byte header followed by tile frames laid end to end.
| Offset | Type | Meaning |
| --- | --- | --- |
| 0 | 4 bytes ASCII | `DTRB` |
| 4 | uint16 LE | bundle format version, 1 |
| 6 | uint16 LE | header length, 16 |
Each frame is an independently compressed tile. Nothing is compressed across
frame boundaries, which is the entire reason for the format: a reader that knows
a frame's offset and length reads exactly that tile and nothing around it.
The bundle deliberately does not describe its own contents. The tile table lives
in `dataset.json`, and a count repeated here would be a second source of truth
able to disagree with it.
## A tile frame
**The frame is one `deflate-raw` stream. The tile header is inside it, not in
front of it** — decompress first, then read the header from the decompressed
bytes.
Decompressed, a tile is a 32-byte header followed by Int16 little-endian samples:
| Offset | Type | Meaning |
| --- | --- | --- |
| 0 | 4 bytes ASCII | `DTRN` |
| 4 | uint16 LE | tile format version, 3 |
| 6 | uint16 LE | header length, 32 |
| 8 | uint16 LE | width in samples |
| 10 | uint16 LE | height in samples |
| 12 | int32 LE | reserved, 0 |
| 16 | uint32 LE | sample count |
| 20 | uint8 | predictor |
Samples are stored row-major, north row first, as differences from a predictor
rather than as absolute values. Predictor 4 is the plane: each sample is written
as its difference from `left + up - upLeft`, using the samples already
reconstructed. A reference off the edge of the tile, or one that is no-data,
counts as zero. Differences wrap through Int16 and reconstruction wraps the same
way, so the round trip is exact.
`-32768` is no-data. A no-data sample is stored as itself, is never used as a
reference, and never has the predictor applied to it.
## Reading one tile
```js
const NO_DATA = -32768;
const PLANE = 4;
async function readTile(bundleUrl, tile) {
const response = await fetch(bundleUrl, {
headers: { Range: `bytes=${tile.offset}-${tile.offset + tile.length - 1}` },
});
const frame = await response.arrayBuffer();
const stream = new Blob([frame]).stream().pipeThrough(new DecompressionStream('deflate-raw'));
const raw = new DataView(await new Response(stream).arrayBuffer());
if (String.fromCharCode(raw.getUint8(0), raw.getUint8(1), raw.getUint8(2), raw.getUint8(3)) !== 'DTRN') {
throw new Error('Not a terrain tile.');
}
const headerBytes = raw.getUint16(6, true);
const width = raw.getUint16(8, true);
const height = raw.getUint16(10, true);
const count = raw.getUint32(16, true);
const predictor = raw.getUint8(20);
if (predictor !== PLANE) throw new Error(`Unsupported predictor ${predictor}.`);
const encoded = new Int16Array(count);
for (let index = 0; index < count; index += 1) {
encoded[index] = raw.getInt16(headerBytes + index * 2, true);
}
return { width, height, values: undoPlane(encoded, width) };
}
function undoPlane(encoded, width) {
const out = new Int16Array(encoded.length);
const at = (index) => (index < 0 || out[index] === NO_DATA ? 0 : out[index]);
for (let index = 0; index < encoded.length; index += 1) {
if (encoded[index] === NO_DATA) {
out[index] = NO_DATA;
continue;
}
const column = index % width;
const left = column === 0 ? 0 : at(index - 1);
const up = index < width ? 0 : at(index - width);
const upLeft = index < width || column === 0 ? 0 : at(index - width - 1);
out[index] = ((encoded[index] + (left + up - upLeft)) << 16) >> 16;
}
return out;
}
```
`deflate-raw` was chosen over zstd for exactly this reason: every browser
decompresses it natively, so reading terrain needs no WebAssembly decoder. On
predicted heights the two land within one percent of each other.
Fetching a whole package instead is two requests and no ranged reads — the
bundle is small enough that this is reasonable when you want all of a cell.
## Heights are game units, not metres
This is the one thing that will silently give wrong answers if it is missed.
Samples are **not** elevations in metres. Before quantisation each elevation is
passed through the piecewise-linear mapping recorded in `gameTransform.verticalMapping`:
| Source elevation | Stored value |
| --- | --- |
| 0 m – 2 m | 0 – 10 |
| 2 m – 10,000 m | 11 – 10,000 |
The first two metres are stretched over ten units because that band is a
shoreline, and a shoreline needs resolution the rest of the range does not.
To recover metres:
```js
function metres(value) {
if (value === -32768) return Number.NaN;
if (value <= 10) return (value / 10) * 2;
return 2 + ((value - 11) / (10000 - 11)) * (10000 - 2);
}
```
Two consequences worth stating plainly:
- **Elevations below sea level are clamped to zero.** The Dead Sea and Death
Valley are flat at the shoreline value, not negative.
- **The mapping is lossy.** Above 2 m a stored unit is about one metre, so the
quantisation is roughly metre-scale — but it is a mapping, not a unit, and
round-tripping it does not return the source exactly.
`gameTransform` also carries `horizontalMetersPerGameUnit` (100),
`sampleSpacingMeters` (0.9, which is the 90 m grid expressed in those units),
`verticalScale` and `verticalReferenceMeters`. Those describe how the samples are consumed by the
game this was built for; a different consumer can ignore them and use the mapping
above.
## Checking a reader
Two packages with known ground, so a new reader can tell a working decoder from
one that merely produces numbers. Take the largest frame in each package's
`tiles`, read it over a ranged request, and convert to metres:
| Package | Where | Largest tile decodes to |
| --- | --- | --- |
| `N046/E008` | Bernese Alps, Switzerland | 228 m – 3,217 m, no no-data |
| `N027/E086` | Khumbu, Nepal | 1,045 m – 6,956 m, no no-data |
A reader that skips the decompression step, reads the header from the compressed
bytes, or forgets to undo the predictor will not produce these ranges — it will
produce noise that still looks like a heightfield.
## Coordinates
Samples sit on an EPSG:6933 grid — a global equal-area projection — at 90 m
spacing, with the grid origin at easting 0, northing 0. Within a package, `x`
increases eastward and `z` increases southward.
Equal-area rather than Web Mercator so that a sample covers the same ground
everywhere, which is what makes 90 m mean 90 m at 60° north as well as at the
equator.
Cell placement is exact by construction: a package covers exactly its degree
cell, so cells tile the Earth without seams or overlap.
## Source and attribution
Heights are derived from the Copernicus DEM GLO-90 global digital surface model,
reprojected and resampled as described above.
> Copernicus WorldDEM-90 © DLR e.V. 2010-2014 and © Airbus Defence and Space
> GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA; all
> rights reserved
This notice is also carried in every package's `dataset.json`. If you use this
dataset, reproduce it. Consult the Copernicus Data Space terms for what your own
use requires.
## Provenance
Every package was produced by the same deterministic pipeline: fetch the GLO-90
source tiles covering the cell, reproject to EPSG:6933 at 90 m with bilinear
resampling, map elevations through the vertical mapping, quantise to Int16,
predict, compress, and bundle. Encoding parameters — plane predictor,
`deflate-raw`, level 6 — were each chosen by measurement rather than left to a
tool's default, and are recorded in every package's `tileFormat` so a reader
never has to be told how a tile was written.
Rebuilding a package from the same source produces the same bytes.