TXG — TEXSPACE GeoArchive Specification (v2)
Status: Stable v2 (TXGR\x02 / TXGS\x02) + Sidecar Archives (TXGZ\x01 / TXGL\x01 / TXGO\x01) Goal: Cloud-native, immutable, HTTP-Range-queryable binary geocoding, timezone, spatial-join, and private-overlay archives that serve planet-scale forward geocoding, address verification, autocomplete, reverse geocoding, point-in-polygon spatial joins, and relational nearby search directly from static object storage (S3, Cloudflare R2, GCS, or local disk) with zero backend servers.
1. Design Principles#
- Minimize HTTP round-trips (2–3 RTTs cold, 1–2 RTTs warm): Every lookup index uses a single-level in-memory fence-key directory embedded in the file's Root Block (
bytes 0..root_end, typically32–128 KB). A client fetches the Root Block once per archive, caches it in memory/IndexedDB, and resolves every subsequent key directly to a single compressed leaf block (16–32 KB) with zero intermediate B-tree hops. - Hilbert-clustered entity & address layout:
- All entities inside a shard are assigned dense sequential IDs (
hilbert_id: u32) ordered byS2CellId(lat, lon)at level 30. Nearby streets, POIs, and addresses share the same32 KBblock, enabling: - Single-range reverse geocoding (
s2_cell-> 1–2ENTSblocks +ADDRblock). - Single-range local fuzzy/typo rescue (fetch the S2 neighborhood's
ENTSblock and run Levenshtein/Metaphone in RAM instead of fetching global trigram lists over HTTP). - High-ratio delta-coordinate compression (
~4–6 bytes/rooftopcompressed).
- All entities inside a shard are assigned dense sequential IDs (
- Deterministic, immutable byte ranges for CDN caching: All leaf blocks have fixed byte offsets computed at build time. Every client querying
"san francisco"or"london"requests the exact sameRange: bytes=start-end, enabling high edge-cache hit ratios on Cloudflare / CloudFront / Fastly. - Sans-I/O execution model: Query planning and decoding are pure Rust (
no C/SQLite dependencies,wasm32-unknown-unknowncompatible). Callers supply any async or sync byte-range transport (fetch()in browsers/Workers,reqwest/HTTP in CLI,pread/mmapon disk).
2. Primitives & Framing#
- Endianness: Little-endian for all fixed-width integers (
u16,u32,u64,i32). - Varints:
uvarint: unsigned LEB128 (u64).svarint: ZigZag-encoded signed LEB128 (i64,(v << 1) ^ (v >> 63)).
- Strings:
uvarint(byte_len)followed by UTF-8 bytes. - Coordinates: Quantized WGS-84 degrees
lat_e7 = round(lat * 1e7) as i32,lon_e7 = round(lon * 1e7) as i32(~1.1 cmprecision). - Compression (
compression: u8):0: Uncompressed raw bytes.1: Raw DEFLATE (RFC 1951).2: Zstandard (RFC 8878).
- Front-coded sorted strings: Within a sorted leaf block, each key is stored as:
uvarint(shared_prefix_bytes) | uvarint(suffix_bytes) | suffix_utf8relative to the immediately preceding key (shared_prefix_bytes = 0for the first entry). - Block reference:
(offset: u64, comp_len: u32, raw_len: u32)— absolute byte rangeoffset .. offset + comp_leninside the archive.
3. Archive Type 1: Global Router (router.txg)#
Maps normalized attribute strings across up to 128 shards and embeds global admin places for zero-shard city/country autocomplete.
3.1 Fixed 64-Byte Header (bytes 0..64)#
| Offset | Size | Field | Description |
|---|---|---|---|
0 | 8 | magic | ASCII TXGR + version \x02\x00\x00\x00 |
8 | 1 | compression | Block compression codec (0, 1, or 2) |
9 | 1 | flags | Bitmask (reserved, 0) |
10 | 2 | shard_count | Number of shards in catalog (<= 128) |
12 | 4 | reserved | 0 |
16 | 8 | root_offset | Byte offset of Root Block (64) |
24 | 8 | root_comp_len | Compressed byte length of Root Block |
32 | 8 | root_raw_len | Uncompressed byte length of Root Block |
40 | 8 | total_attrs | Total normalized routing attributes across all blocks |
48 | 8 | total_admins | Total global admin entries across all blocks |
56 | 8 | created_unix | Build timestamp (Unix seconds UTC) |
3.2 Router Root Block (compressed)#
- Shard Catalog (
uvarint(shard_count)entries):shard_id: String(e.g."us_ca")rel_path: String(e.g."shards/us_ca.txg")min_lat_e7: i32, min_lon_e7: i32, max_lat_e7: i32, max_lon_e7: i32entity_count: uvarint,address_count: uvarintshard_root_end: uvarint(exact byte length of shard header + root so clients fetch it in 1 Range read)
- Attribute-Shard Fence Directory (
uvarint(n_blocks)entries):- Front-coded
first_key: String(lexicographically smallestattr_normin block) offset_delta: uvarint(delta from previous block'soffset + comp_len, base =root_offset + root_comp_len)comp_len: uvarint,raw_len: uvarint
- Front-coded
- Admin-Place Fence Directory (
uvarint(n_admin_blocks)entries):- Same front-coded fence format for global admin/landmark blocks.
3.3 Attribute-Shard Leaf Blocks (~24 KB compressed)#
uvarint(entry_count)- Sorted front-coded entries:
shared_prefix: uvarint,suffix: Stringmask_tag: u8:1..=8: sparse list ofmask_tagshard indices (u8each)0xFF: dense 16-byte little-endianu128shard bitmask
3.4 Admin-Place Leaf Blocks (~20 KB compressed)#
uvarint(entry_count)- Sorted front-coded entries by
name_norm:shared_prefix: uvarint,suffix: String(normalized key)display_name: String(empty means reusename_norm)layer: u8,pop_q8: u8,shard_idx: u8lat_e7: i32,lon_e7: i32
4. Archive Type 2: Spatial Shard (<shard>.txg)#
Self-contained archive for one geographic shard (usable standalone or routed via router.txg).
4.1 Fixed 64-Byte Header (bytes 0..64)#
| Offset | Size | Field | Description |
|---|---|---|---|
0 | 8 | magic | ASCII TXGS + version \x02\x00\x00\x00 |
8 | 1 | compression | Block compression codec (0, 1, or 2) |
9 | 1 | flags | Bitmask (reserved, 0) |
10 | 2 | reserved_u16 | 0 |
12 | 4 | entity_count | Total Hilbert-ordered entities in shard |
16 | 8 | root_offset | Byte offset of Root Block (64) |
24 | 8 | root_comp_len | Compressed byte length of Root Block |
32 | 8 | root_raw_len | Uncompressed byte length of Root Block |
40 | 8 | address_count | Total rooftop/parcel addresses in shard |
48 | 8 | attr_count | Total normalized attributes in shard |
56 | 8 | created_unix | Build timestamp (Unix seconds UTC) |
4.2 Shard Root Block (compressed)#
- Shard Metadata:
shard_id: String,min_lat_e7..max_lon_e7: 4×i32,macro_admin_ref: (offset, comp_len, raw_len). ATTRFence Directory: front-codedfirst_attr_norm+ block(offset, comp_len, raw_len).POSTSpill Block Directory:(first_s2_cell: u64, last_s2_cell: u64, offset, comp_len, raw_len)indexed byu32block ID.ENTSHilbert Fence Directory:(first_hilbert_id: u32, first_s2_cell: u64, last_s2_cell: u64, offset, comp_len, raw_len).ADDRFence Directory:(first_street_hilbert_id: u32, first_hn_key: u64, offset, comp_len, raw_len).ADMINLocal Fence Directory:(first_s2_cell: u64, last_s2_cell: u64, offset, comp_len, raw_len).
4.3 Section 1 — ATTR Leaf Blocks (~16 KB compressed)#
Sorted by attr_norm. Each entry:
- Front-coded
attr_norm idf_q8: u8(round(idf * 10.0).clamp(0, 255))entity_count: uvarintfootprint_cell_count: uvarint, followed by sorted S2 CellUnion cell IDs encoded assvarintdeltas (firstrawu64, subsequent deltas)posting_mode: u8:0(inline,entity_count <= 24):uvarint(pair_count)+ sorted(s2_cell_delta, hilbert_id)pairs1(spilled intoPOST):uvarint(first_post_block_idx)+uvarint(post_block_count)
4.4 Section 2 — POST Spill Blocks (~16 KB compressed)#
For high-frequency attributes (entity_count > 24), postings are sorted by (s2_cell_id, hilbert_id) and split into 16 KB blocks. The Root Block's POST directory records (first_s2_cell, last_s2_cell) per chunk so clients skip chunks outside the query's S2 focus.
4.5 Section 3 — ENTS Blocks (~32 KB compressed)#
Entities sorted by (s2_cell_l30(lat, lon), layer, original_entity_id). Block b starts at first_hilbert_id. Each entry:
s2_cell_delta: uvarint(delta from previous entity'ss2_cell_l30)layer: u8,source: u8,pop_q8: u8,flags: u8flags & 0x01(ENT_FLAG_HAS_ADDRS): has rooftop/parcel addresses inADDRflags & 0x02(ENT_FLAG_HAS_POLYLINE): has compact street polyline (for interpolation & reverse snapping)flags & 0x04(ENT_FLAG_SAME_PARENTS): inherits the immediately preceding entity's[country, region, county, locality]ADMIN_MACROindices in 0 bytes (~98% hit rate along the Hilbert curve)
lat_e7_delta: svarint,lon_e7_delta: svarintname: String- If
flags & 0x02:uvarint(vertex_count)+ delta-encoded(dlat_e7, dlon_e7)polyline vertices (max 32 simplified vertices). - If
flags & 0x04 == 0: 4 ×uvarint(idx + 1, with0encodingNO_ADMIN) giving precomputed full-resolution[country, region, county, locality]indices intoADMIN_MACRO.
4.6 Section 4 — ADDR Blocks (~16 KB compressed)#
Sorted by (street_hilbert_id, hn_sort_key) where hn_sort_key = (numeric_prefix as u64) << 16 | suffix_hash16. Each block begins with a mini postcode dictionary (uvarint(n_pcs) + strings) followed by uvarint(addr_count) entries:
street_hilbert_id_delta: uvarinthousenumber: Stringdlat_e7: svarint,dlon_e7: svarintpostcode_idx: uvarint(0= empty,1..=n_pcs= dictionary index)addr_flags: u8:addr_flags & 0x01(ADDR_FLAG_IS_PARCEL): cadastral parcel, followed byapn: Stringaddr_flags & 0x02(ADDR_FLAG_CUSTOM_LOCALITY): cross-border arterial override, followed byuvarint(locality_macro_idx + 1)when a rooftop belongs to a different full-resolutionADMIN_MACROlocality than its parent street centroid (e.g. Mission St crossing San Francisco / Daly City)
4.7 Section 5 — ADMIN & ADMIN_MACRO Blocks (~24–32 KB compressed)#
ADMIN_MACRO(1 block per shard, cached once): allCountry,Region,County, andLocalityentities in the shard with simplified exterior polygon rings (delta-e7vertices). Referenced in O(1) at runtime via precomputed full-resolutionparent_admins/locality_overrideindices computed once at pack time before polygon simplification.ADMINLocal Blocks (sorted bys2_cell_l30):Macrohood,Neighbourhood, andPostalCodeentities with simplified exterior polygon rings (or point-only centroids) for fine-grained reverse geocoding and display label enrichment.
5. Archive Type 3: Timezone Archive (tz.txg, magic TXGZ)#
Packs all 444 IANA timezone polygon boundaries plus RFC 8536 TZif v2/v3 DST rule blobs into a single static HTTP-Range file (~4.6 MB).
5.1 Fixed 32-Byte Header (bytes 0..32)#
| Offset | Size | Field | Description |
|---|---|---|---|
0 | 8 | magic | ASCII TXGZ + version \x01\x00\x00\x00 |
8 | 1 | compression | Block compression codec (1 = Deflate) |
9 | 3 | reserved | 0 |
12 | 8 | root_offset | Byte offset of Root Block (32) |
20 | 4 | root_comp_len | Compressed byte length of Root Block (~22 KB) |
24 | 4 | root_raw_len | Uncompressed byte length of Root Block |
28 | 4 | reserved | 0 |
5.2 Root & Data Blocks#
- Initial Probe (
64 KiB): Fetches the header and complete Root Block in 1 RTT (zones: Vec<(tzid, tzif_block)>+polys: Vec<(zone_idx, bbox_e7, poly_block)>). - Polygon Blocks: Delta-E7 exterior ring + hole rings compressed with Deflate; only
1–2bbox-overlapping polygons and their tiny TZif rule blobs are fetched in Round 2. - Ocean fallback: Coordinates matching zero polygons resolve in 0 extra RTTs to nautical
Etc/GMT±N.
6. Archive Type 4: Polygon Spatial-Join Layer (*.txg, magic TXGL)#
"PMTiles for Point-in-Polygon" — packs any GeoJSON FeatureCollection or .geojsonl of Polygon / MultiPolygon features with arbitrary JSON properties (texspace pack-layer) into a single immutable HTTP-Range file.
6.1 Fixed 32-Byte Header (bytes 0..32)#
| Offset | Size | Field | Description |
|---|---|---|---|
0 | 8 | magic | ASCII TXGL + version \x01\x00\x00\x00 |
8 | 1 | compression | Block compression codec (1 = Deflate) |
9 | 3 | reserved | 0 |
12 | 4 | feature_count | Total polygon/multipolygon features |
16 | 4 | root_comp_len | Compressed byte length of Root Block (at offset 32) |
20 | 4 | root_raw_len | Uncompressed byte length of Root Block |
24 | 8 | created_unix | Build timestamp (Unix seconds UTC) |
6.2 Root Directory & Bundled Feature Blocks#
- Root Block (
bytes 32 .. 32 + root_comp_len, written via two-pass exact reservation):layer_name: String,description: String,uvarint(feature_count)- Entries sorted smallest bbox area first (nested enclaves match ahead of enclosing zones):
id: String | 4×i32 (min_lat_e7..max_lon_e7) | BlockRef(offset, comp_len, raw_len)
- Feature Block (1 Range read fetches BOTH properties and geometry):
properties_json: String(arbitrary JSON object preserved verbatim)uvarint(polygon_count)→ for each polygon: delta-E7exterior_ring+uvarint(hole_count)+ delta-E7hole_rings
- Single-RTT small archives: Initial probe is
64 KiB(LAYER_INITIAL_PROBE_BYTES); anyTXGLarchive<= 64 KiBserves header, root, and all feature blocks from a single HTTP 206 read.
7. Archive Type 5: Private Overlay Archive (*.txg, magic TXGO)#
Packs private CSV, TSV, or GeoJSON site catalogs (stores, warehouses, EV chargers, hubs; texspace pack-overlay) into a single S2 Hilbert-clustered + term-indexed static HTTP-Range archive that fuses seamlessly into search, autocomplete, reverse, and nearby.
7.1 Fixed 32-Byte Header (bytes 0..32)#
| Offset | Size | Field | Description |
|---|---|---|---|
0 | 8 | magic | ASCII TXGO + version \x01\x00\x00\x00 |
8 | 1 | compression | Block compression codec (1 = Deflate) |
9 | 3 | reserved | 0 |
12 | 4 | site_count | Total Hilbert-ordered private sites |
16 | 4 | root_comp_len | Compressed byte length of Root Block (at offset 32) |
20 | 4 | root_raw_len | Uncompressed byte length of Root Block |
24 | 8 | created_unix | Build timestamp (Unix seconds UTC) |
7.2 Root Directory, Site Blocks & Term Blocks#
- Root Block:
name: String,description: String,bbox_e7: 4×i32,site_count: uvarint,site_fences: Vec<(first_site_idx, last_site_idx, first_s2, last_s2, BlockRef)>(128 S2-sorted sites/block — enables both O(1) ID lookup and S2 capnearbyscans)term_fences: Vec<StrFence>(256 alphabetically sorted terms/block — supports exact, prefix, and bounded Damerau-Levenshtein fuzzy lookup in RAM)
- Site Blocks: Delta
site_idx,s2_cell_l30: u64,lat_e7: i32,lon_e7: i32,id,name,category,address,properties_json. - Term Blocks: Sorted
(term: String, delta_encoded site_indices: Vec<u32>).
8. Query Execution & Wire Budget#
| Operation | Typical RTTs (Cold / Warm) | Typical Wire Transfer |
|---|---|---|
Boot (router.txg header + 262 KB root via 384 KiB probe) | 1 / 0 (cached) | ~384 KB once (cached across sessions) |
| Global Forward / Verify (440-query Third-Party Global Holdout) | 6–7 / 4 p50 | 255 KB p50 warm session (12 ranges) |
Global Reverse (37.72047, -122.43765) | 3 / 1–2 | ~64–110 KB cold / ~32–64 KB warm |
Focused Autocomplete ("4865 Miss") | 2–4 / 1 | ~32–80 KB |
Timezone (tz.txg) or Spatial Join (TXGL) | 1–2 / 0–1 | ~64 KB probe (+ 1–2 feature blocks if > 64 KB) |
Parallel enrich() (Reverse + TZ + Spatial + 2 TXGL layers) | 4 / 1–2 | Coalesced across all archives in parallel Promise.all rounds |
Private Overlay (TXGO <= 64 KB) / In-Memory mountGeoJSON | 1 / 0 | <= 64 KB once (or 0 B in RAM) |