/ altpbf

altpbf โ€” Elevation Tile Format

Protocol Buffers-based raster elevation tiles.
3-tier zoom LOD ยท GEBCO + ALOS (+ GSI DEM10B in Japan) ยท Int16 delta + deflateRaw ยท Worker zero-copy

Table of Contents
  1. What is altpbf?
  2. Data Sources
  3. 3-Tier Tile Hierarchy
  4. Binary Format
  5. Tile Naming
  6. Worker & Cache Architecture
  7. GEBCO Processing Pipeline
  8. API Reference

1. What is altpbf?

altpbf is a binary raster elevation tile format built on Protocol Buffers. Where GeoPBF handles vector geometry (coastlines, roads, polygons), altpbf handles raster elevation grids โ€” the digital elevation model (DEM) and bathymetry data needed for terrain rendering, shadow calculation, and 3D visualization.

Each tile is a rectangular grid of Int16 elevation values (meters), delta-encoded and compressed with deflateRaw. Three tile sizes cover the globe at different resolutions, and the ortho-earth engine selects the appropriate tier automatically based on zoom level.

The altpbf npm package (1.2.0) is the format only: encode, decode, encodeName / decodeName and altpbf2png. It is written in TypeScript (strict) and ships type definitions (AltpbfTile, AltpbfDecoded, AltpbfSource, Altpbf2PngOptions, โ€ฆ). Its only runtime dependency is geopbf; it needs CompressionStream, and altpbf2png also needs OffscreenCanvas. Fetching, caching, worker decoding and height lookup (createGetHeight, createTileLoader) live in the engine, @ortho-earth/core/elevation.

Why Int16?

Earth's elevation range is roughly โˆ’11,000 m (Mariana Trench) to +8,849 m (Everest). A signed 16-bit integer covers โˆ’32,768 to +32,767 m โ€” exactly enough, with no wasted bits. Compared to Float32, Int16 halves the data size before any compression is applied.

2. Data Sources

SourceCoverageResolutionUsed for
GEBCO
General Bathymetric Chart of the Oceans
Global (land + sea) ~450 m (15 arc-sec) HGT90 ยท HGT10
ALOS AW3D30
JAXA ALOS World 3D
Land only ~30 m (1 arc-sec) HGT01
GSI DEM10B
Geospatial Information Authority of Japan
Japan only (bare earth) ~10 m, baked to a 1โ€ณ grid HGT01 (Japan) ยท HGT10 (Japan, merged with GEBCO)

GEBCO provides global coverage including ocean bathymetry, making it the baseline for all zoom levels. ALOS AW3D30 is a high-precision land-only DEM published by JAXA, used for close-up terrain rendering where its 30 m resolution delivers visually meaningful detail. Since ALOS tiles only exist for land areas, the engine keeps an index of available tiles and falls back gracefully to GEBCO HGT10 for ocean queries. In Japan, HGT01 tiles are re-baked from GSI DEM10B (bare-earth DTM, where AW3D30 is a surface model) and stored in the bucket; the engine reads the bucket first and only falls back to JAXA when no baked tile exists.

3. 3-Tier Tile Hierarchy

altpbf defines three tile sizes, each covering a different angular extent of the globe. createGetHeight (@ortho-earth/core/elevation) switches between tiers based on the current zoom level, defaulting to level1 = 7 and level2 = 12.

HGT90
90ยฐ tile
Global overview โ€” GEBCO
Only 8 tiles cover the globe. Downsampled 8ร— from the 21600-px source (average pooling). Fastest to load.
zoom < 7
HGT10
10ยฐ tile
Regional โ€” GEBCO
648 tiles cover the globe (81 per 90ยฐ quadrant). Latitude-adjusted width (polar shrink). Sub-100 km features become visible.
7 โ‰ค zoom < 12
HGT01
1ยฐ tile
Local detail โ€” ALOS AW3D30 (GSI DEM10B in Japan)
One tile per 1ยฐ land cell in JAXA's AW3D30 list, 30 m resolution. Only exists for land areas; falls back to HGT10 otherwise.
zoom โ‰ฅ 12

Each tier is a strict fallback chain: HGT01 โ†’ HGT10 โ†’ HGT90. If a high-resolution tile is unavailable (ocean, no ALOS data) or returns no elevation, the next coarser tier answers the query transparently. The caller always receives a valid elevation value.

Bilinear Interpolation

Within each tile, calcHeight(x, y, v) performs bilinear interpolation across the four nearest grid cells โ€” no staircase artifacts. Normalized coordinates (0โ€“1) within the tile are computed from the raw lat/lng and passed directly to the interpolation function.

4. Binary Format

Each .altpbf tile is a deflateRaw-compressed Protocol Buffers message.

Header
tile metadata
NAME (1) ยท SOURCE (2) ยท WIDTH (3) ยท HEIGHT (4)
LNG (5) ยท LAT (6) ยท RANGE (7)
All coordinate fields use signed Varint (SVarint)
โ†“
DATA (10)
elevation grid
Packed SVarint โ€” delta-encoded Int16 elevation values
Row-major order, top-to-bottom ยท width ร— height values total
โ†“
deflateRaw
whole message
Raw DEFLATE (no gzip header) via deflateRaw / inflateRaw
Inflated before PBF parsing

4.1 Delta Encoding for Elevation

Terrain elevation changes gradually โ€” neighboring cells in a DEM rarely differ by more than a few tens of metres. Delta encoding exploits this locality: storing differences rather than absolute values keeps numbers small, and small numbers encode to fewer Varint bytes.

Raw Int16 (m)
1240
1255
1268
1241
1195
Delta
1240
+15
+13
โˆ’27
โˆ’46
SVarint bytes
2 bytes
1 byte
1 byte
1 byte
1 byte

After delta encoding, most values in a smooth terrain tile fit in a single Varint byte. Combined with deflateRaw on top, altpbf tiles are typically 5โ€“15ร— smaller than an equivalent raw Int16 array.

decode reads the packed SVarint body straight into the output Int16Array โ€” no intermediate JS arrays โ€” using a small embedded WebAssembly kernel (SIMD128 where available, scalar wasm otherwise) with a plain-JS fallback when wasm is unavailable (e.g. blocked by CSP). A 5.7M-point HGT10 tile decodes in ~21 ms / +12 MB instead of ~99 ms / +230 MB with the previous implementation.

4.2 Elevation Color Map

altpbf2png renders a tile as a PNG image using altitude/depth step colors:

Deep
< โˆ’6000 m
Ocean
โˆ’2000 to โˆ’6000 m
Slope
โˆ’200 to โˆ’2000 m
Shelf
0 to โˆ’200 m
Lowland
0โ€“200 m
Hill
200โ€“500 m
Upland
500โ€“1000 m
Highland
1000โ€“2000 m
Alpine
2000โ€“4000 m
Peaks
4000โ€“6000 m
Snow
> 6000 m

5. Tile Naming

Each tile is uniquely identified by a compact name string encoding its range, latitude, and longitude:

encodeName(lng, lat, range)
// range > 0  โ†’  "R{02d(range)}{lat_prefix}{03d(|lat|)}{lng_prefix}{03d(|lng|)}"
// range omitted / 0  โ†’  "{lat_prefix}{03d(|lat|)}{lng_prefix}{03d(|lng|)}"  (key of the JAXA AW3D30 index)
// (lng, lat) is the tile's bottom-left (south-west) corner; decodeName(name) โ†’ [lng, lat, range]

// Examples:
encodeName(0, -90, 90)  // โ†’ "R90S090E000"  (HGT90 quadrant 0โ€“90ยฐE ยท 0โ€“90ยฐS)
encodeName(130, 30, 10)  // โ†’ "R10N030E130"  (HGT10 Japan region)
encodeName(135, 35, 1)   // โ†’ "R01N035E135"  (HGT01, Kinki region)
encodeName(135, 35)      // โ†’    "N035E135"  (AW3D30 index key)
decodeName("R01N035E135")   // โ†’ [135, 35, 1]
ALOS Tile Existence Check

ALOS AW3D30 tiles exist only over land. Before requesting an HGT01 tile, the engine checks an in-memory index loaded from the JAXA tile list (index_alos() in @ortho-earth/core/elevation, cached in IndexedDB). Ocean queries immediately fall back to HGT10 without a network round-trip. If JAXA is unreachable, the engine continues with an empty index and refetches it in the background.

6. Worker & Cache Architecture

Request
getHeight(lng, lat, zoom)
select tier by zoom
โ†’
L1 Cache
IndexedDB
"GIS/alt" namespace
decoded objects
โ†’ miss โ†’
Worker
elevation/worker.ts
load + decode
Int16Array transfer
โ†’
L2 Storage
nativeBucket
server-side bucket
"GIS/alt" ยท JAXA for HGT01
// packages/ortho-core/src/elevation/worker.ts โ€” zero-copy Int16Array transfer to main thread
import { load, setApiUrl } from "./loader.ts";
onmessage = async e => {
	const { name, apiUrl } = e.data;
	if (apiUrl) setApiUrl(apiUrl);
	try { const obj = await load(name);
		obj ? postMessage(obj, [obj.data.buffer])  // โ† Transferable: zero-copy
			: postMessage(null);
	} catch (e) { postMessage(null); }
};

The worker inflates and decodes the tile off-main-thread, then transfers the Int16Array buffer back via the Transferable interface โ€” no copying, no serialization. The worker runs under the engine's "ortho:height" worker role. createGetHeight uses a single worker that handles requests one at a time; while a load is in flight, render-side queries return 0 until it arrives, and { wait: true } callers wait for it. createTileLoader (used by the terrain atlas) runs a pool of up to 3 workers, merges concurrent requests for the same tile, and decodes in-thread when nested workers are unavailable. Once decoded, tiles are persisted to IndexedDB for instant re-use across sessions.

7. GEBCO Processing Pipeline

The raw GEBCO source is a set of GeoTIFFs at 21,600 ร— 21,600 pixels per 90ยฐ quadrant (eight quadrants, 86,400 ร— 43,200 for the globe). The uploader app's GEBCO() function (apps/uploader/src/terrain/gebco.ts, not part of the altpbf package) downloads and tiles it into altpbf format:

// Step 1 โ€” HGT90: 8ร— average-pool downsampling
// 21600 ร— 21600 โ†’ 2700 ร— 2700  (one 90ยฐ tile per quadrant)
// Each output pixel = mean of 8ร—8 source pixels

// Step 2 โ€” HGT10: extract 9ร—9 = 81 sub-tiles per quadrant (2400 px tall)
// Apply polar width shrink so tiles remain square on-screen
// shrink(lat): fraction of full-width actually used at that latitude

7.1 Polar Width Correction

Meridians converge toward the poles, so a 10ยฐ longitude span represents far fewer kilometres at high latitudes than at the equator. GEBCO HGT10 tile generation compensates by reducing the pixel width of polar tiles:

ยฑ80ยฐ
17%
ยฑ70ยฐ
33%
ยฑ60ยฐ
50%
ยฑ50ยฐ
67%
ยฑ40ยฐ
100%
equator
100%

Tile pixel width relative to equatorial baseline. Polar tiles are narrower, matching the reduced real-world extent per degree of longitude.

8. API Reference

// โ”€โ”€ altpbf (npm) โ€” the format โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
import { encode, decode, encodeName, decodeName, altpbf2png } from "altpbf";
import type { AltpbfTile, AltpbfDecoded, AltpbfSource, AltpbfColorMap, Altpbf2PngOptions } from "altpbf";

// โ”€โ”€ createGetHeight โ€” engine entry point (@ortho-earth/core/elevation) โ”€โ”€
import { createGetHeight } from "@ortho-earth/core/elevation";
const getHeight = await createGetHeight({
	apiUrl:  'https://your-api.example.com',  // nativeBucket base URL
	level1:  7,    // zoom threshold HGT90 โ†’ HGT10
	level2:  12,   // zoom threshold HGT10 โ†’ HGT01
	onstart: name => console.log(`loading ${name}...`),
	onend:   name => console.log(`done ${name}`),
});

// Query elevation at any (lng, lat, zoom)
const h = await getHeight(139.77, 35.68, 14);  // โ†’ height in metres

// Zoom omitted โ†’ always use highest resolution (HGT01)
const h = await getHeight(139.77, 35.68);

// โ”€โ”€ altpbf2png โ€” render tile as PNG โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
const blob = await altpbf2png(pbfBlob, {
	size:     256,         // output PNG size (square)
	colorMap: h => [r, g, b] // custom color function (optional)
});

// โ”€โ”€ Low-level encode / decode โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
const buf = await encode({ name, source, lng, lat, range, width, height, data });  // โ†’ Uint8Array
const obj = await decode(blob);  // โ†’ { name, source, lng, lat, range, width, height, data: Int16Array }

// โ”€โ”€ GEBCO bulk tile generation (apps/uploader) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
await GEBCO({ year: 2026, noIce: false, log: console });
// Downloads ~12 GB source, generates HGT90 + HGT10 altpbf tiles, uploads to bucket

// โ”€โ”€ ALOS tile index (engine-internal, elevation/loader.ts) โ”€โ”€
const index = await index_alos();
// โ†’ { "N035E135": "v2404", "N036E135": "v2404", ... }

altpbf 1.2.0 ยท Kenji Yoshida ยท MIT License ยท 2026