Terra index structure
Every location in Saudi Arabia can be expressed as a Terra cell — a 64-bit unsigned integer encoding the cell's resolution, base cell, and hierarchical position. Terra provides two human-readable string representations of this integer, each optimised for a different audience.
The 64-bit cell index
Internally, every Terra cell is a uint64_t. All arithmetic in terra-core operates on this integer directly — no string parsing, no geometry lookup.
| Bits | Field | Description |
|---|---|---|
| 63–60 | Mode | 0001 = Terra hexagon cell |
| 59–56 | Reserved | 0000 in Terra v1 |
| 55–52 | Resolution | 0–14; value 15 reserved |
| 51–45 | Base cell | 0–127; ~80 base cells cover KSA + GCC buffer |
| 44–3 | Child digits | 14 × 3 bits (values 0–6); digits below current resolution padded with 7 |
| 2–0 | Reserved | Zero in Terra v1 |
Extract the resolution with a single bitwise operation:
int terra_get_resolution(TerraIndex cell) {
return (int)((cell >> 52) & 0xF);
}
Child digits
Each digit (0–6) identifies which of the 7 children was selected at each level. Digit 0 is the centre child; digits 1–6 are the surrounding children. Digits beyond the current resolution are padded with 7, so parent cells can be derived from children using a mask operation without any coordinate lookup.
Terra Index String — TIS
The TIS is the developer-facing string form: a lowercase t prefix followed by the 64-bit integer encoded as 16 hex characters.
t10830cd1943ffff8
- Always 17 characters, at every resolution.
- Resolution is implicit in the bit field — readable with
terra_get_resolution(). - Used by all terra-core bindings, PostGIS storage, API responses, and DuckDB.