Expand description
Variable-precision geographic location encoding.
NodeLocation represents a geographic position as a 1–7 byte grid code.
Each byte refines the location to a 16×16 sub-grid of the parent cell, with the
high nibble indexing longitude and the low nibble indexing latitude.
The encoding has a useful truncation property: dropping trailing bytes gives the correct lower-precision encoding of the same position — no recomputation needed.
§Encoding
For a given precision N (1–7 bytes), two 4N-bit indices are computed:
lon_index = floor((lon + 180) × 16^N / 360)
lat_index = floor((lat + 90) × 16^N / 180)Nibbles are extracted most-significant-first into bytes:
byte[k] = ((lon_index >> (4×(N-1-k))) & 0xF) << 4
| ((lat_index >> (4×(N-1-k))) & 0xF)§Precision
| Bytes | Equator cell size (approx.) |
|---|---|
| 1 | 2,500 × 1,250 km |
| 2 | 156 × 78 km |
| 3 | 9.8 × 4.9 km |
| 4 | 610 × 305 m |
| 5 | 38 × 19 m |
| 6 | 2.4 × 1.2 m |
| 7 | 15 × 7.5 cm |
§Feature: f64
By default all floating-point arithmetic uses f32, which is adequate for
precisions 1–5 (cells ≥ 19 m). Enable the f64 crate feature for accurate
encoding and decoding at 6–7 byte precision.
Structs§
- Node
Location - A variable-precision geographic location encoded as a 1–7 byte grid code.
Constants§
- MAX_
PRECISION - Maximum supported precision in bytes.