Module location

Module location 

Source
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

BytesEquator cell size (approx.)
12,500 × 1,250 km
2156 × 78 km
39.8 × 4.9 km
4610 × 305 m
538 × 19 m
62.4 × 1.2 m
715 × 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§

NodeLocation
A variable-precision geographic location encoded as a 1–7 byte grid code.

Constants§

MAX_PRECISION
Maximum supported precision in bytes.