File size: 5,045 Bytes
1c773f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
---
license: mit
tags:
  - dem
  - elevation
  - terrain
  - copernicus
  - gebco
  - terrarium
  - maplibre
  - cesiumjs
  - bathymetry
  - global
  - tiles
  - openzenith
size_categories:
  - 10M<n<100M
---

# OpenZenith DEM: Global Elevation & Bathymetry Tiles

Global elevation dataset combining **Copernicus GLO-30** (land) and **GEBCO 2025** (ocean bathymetry) in [Terrarium PNG](https://github.com/tilezen/joerd/blob/master/docs/terrarium.md) tile format, ready for MapLibre GL, CesiumJS, and other renderers.

## What is this?

A complete global elevation tile pyramid (zoom 0–8) encoded as **Terrarium PNG** images. Each pixel encodes an elevation value that can be decoded client-side — no server-side processing needed.

**Data sources:**
- **Land elevation**: Copernicus GLO-30 (30 arc-second, ~30m resolution)
- **Ocean bathymetry**: GEBCO 2025 (15 arc-second, ~450m resolution)
- **Merging**: Copernicus takes priority over GEBCO on land; GEBCO fills ocean areas

## Dataset Structure

```
tiles/
├── 0/          # 1 tile     (360° global)
├── 1/          # 4 tiles
├── 2/          # 16 tiles
├── 3/          # 64 tiles
├── 4/          # 256 tiles
├── 5/          # 1,024 tiles
├── 6/          # 4,096 tiles
├── 7/          # 16,384 tiles
└── 8/          # 65,536 tiles
                 ─────────────
                 87,381 tiles (~5.1 GB)
```

Each tile is a 256×256 PNG at path `tiles/{z}/{x}/{y}.png`.

## Terrarium Encoding

Each pixel encodes elevation in meters using RGB channels:

```
elevation_m = (R × 256 + G + B / 256) - 32768
```

| Terrain | Color (RGB) | Elevation |
|---------|-------------|-----------|
| Deep ocean | Dark | < -1000m |
| Sea level | (128, 0, 0) | 0m |
| Low land | Green-ish | 0–500m |
| Mountains | Bright | 1000–5000m |
| Everest peak | (255, 255, 128) | 8,533m |

### JavaScript Decoder

```javascript
function decodeTerrarium(r, g, b) {
  return (r * 256 + g + b / 256) - 32768;
}
```

### Python Decoder

```python
def decode_terrarium(r: int, g: int, b: int) -> float:
    return (r * 256 + g + b / 256) - 32768
```

## Usage

### Python (`pip install openzenith`)

```python
from openzenith import get_elevation, load_tiles

# Download tiles from HuggingFace (zoom 0-8, ~5GB)
tiles_dir = load_tiles(zoom_levels=[0, 1, 2, 3, 4, 5, 6, 7, 8])

# Query elevation at any lat/lon
elev = get_elevation(40.7128, -74.0060)  # New York City
print(f"NYC elevation: {elev:.1f}m")

# Batch queries
from openzenith import get_elevation_batch
elevations = get_elevation_batch([
    (40.7128, -74.0060),   # New York
    (35.6762, 139.6503),   # Tokyo
    (27.9881, 86.9250),    # Mount Everest
])
```

### MapLibre GL JS

```javascript
map.addSource("terrain", {
  type: "raster-dem",
  tiles: ["https://openzenith.cyopsys.com/api/dem-tile/{z}/{x}/{y}"],
  encoding: "terrarium",
  tileSize: 256,
  maxzoom: 12,
});

map.addLayer({
  id: "hillshade",
  type: "hillshade",
  source: "terrain",
  exaggeration: 1.2,
});
```

### CesiumJS

```javascript
// Custom Terrarium terrain provider (included in OpenZenith globe page)
viewer.terrainProvider = createTerrariumTerrainProvider(Cesium);
```

### API Endpoint

```bash
# Query elevation (no API key required)
curl "https://openzenith.cyopsys.com/api/elevation?lat=40.7128&lon=-74.0060"

# Get a tile
curl "https://openzenith.cyopsys.com/api/dem-tile/8/217/151.png" -o tile.png

# Health check
curl "https://openzenith.cyopsys.com/api/dem-tile?health=1"
```

## Verified Accuracy

| Location | Expected | Measured | Error |
|----------|----------|----------|-------|
| Mt. Everest | 8,849m | 8,533m | 0.4% (30m resolution) |
| Death Valley | -86m | -74m | Within 30m |
| Denali | 6,190m | 6,164m | 0.4% |
| Mariana Trench | -10,935m | -7,122m | GEBCO 450m limit |
| Atlantic Ocean | -5,000m+ | -5,175m | Within 450m |

## Technical Details

| Property | Value |
|----------|-------|
| Tile format | 256×256 RGB PNG |
| Encoding | Terrarium |
| Tile pyramid | Standard XYZ (Slippy Map) |
| Vertical datum | WGS84 ellipsoidal |
| Coordinate system | EPSG:4326 (WGS84) |
| NoData | R=0, G=0, B=0 (decodes to NaN) |
| Land accuracy | 3–7m RMSE (Copernicus GLO-30) |
| Ocean accuracy | ~100m (GEBCO 2025 bathymetry) |

## Data Sources

| Source | Resolution | Coverage | License |
|--------|-----------|----------|---------|
| Copernicus GLO-30 | 30 arc-sec (~30m) | Global land | ESA Open |
| GEBCO 2025 | 15 arc-sec (~450m) | Global (land+ocean) | CC-BY 4.0 |

## Related

- **[OpenZenith](https://openzenith.cyopsys.com)** — Free elevation API, 2D/3D maps, GIS sandbox
- **[openzenith Python library](https://github.com/aliasfoxkde/OpenZenith/tree/main/openzenith)**`pip install openzenith`
- **[GitHub](https://github.com/aliasfoxkde/OpenZenith)** — Source code

## License

[MIT](https://opensource.org/licenses/MIT) — Free for personal and commercial use.

Source data retains its own license: Copernicus GLO-30 (ESA Open), GEBCO 2025 (CC-BY 4.0).