Bgrid Protocol
Technical Specification
This document defines the BGrid protocol for geospatial indexing. It is intended for developers who wish to implement BGrid in any programming language.
1. Overview
BGrid is a hierarchical spatial index that maps latitude/longitude coordinates to a sequence of 11-bit integers (1-2048). These integers are typically represented by words from the BIP39 wordlist.
- Input: WGS84 Coordinates (Latitude, Longitude)
- Output: Array of indices where .
2. Coordinate System
- Latitude range: representing South to North.
- Longitude range: representing West to East.
- Datum: WGS84 is assumed.
3. Grid Structure
The grid is defined recursively. At each level, the parent cell is subdivided into a fixed number of child cells.
Subdivision Strategy
To minimize distortion (keeping cells roughly square), the subdivision factors alternate between levels:
| Level | Columns () | Rows () | Total Cells | Aspect Ratio Correction |
|---|---|---|---|---|
| Odd (1, 3, …) | 64 | 32 | 2048 | Wide (2:1) |
| Even (2, 4, …) | 32 | 64 | 2048 | Tall (1:2) |
Since the Earth’s latitudinal span (180°) is half its longitudinal span (360°), the initial 64x32 grid produces cells with a generic 1:1 aspect ratio at the equator. Alternating maintains this relative balance.
4. Encoding Algorithm
To convert a coordinate (Lat, Lon) to a BGrid path of depth :
Initialization
Normalize the coordinates to the unit interval :
Iteration
For each level from 1 to :
-
Determine Divisors:
- If is odd:
- If is even:
-
Calculate Cell Indices:
-
Clamp Indices (Handle edge cases like +180 lon):
-
Compute 1-based Index:
-
Update Normalized Coordinates (Zoom in for next iteration):
-
Append to result.
5. Decoding Algorithm
To convert a BGrid path back to a coordinate and bounds:
Initialization
Start with global bounds:
Iteration
For each level corresponding to index :
-
Adjust to 0-based index:
-
Determine Divisors:
- If is odd:
- If is even:
-
Decode Row/Col:
-
Calculate Cell Dimensions:
-
Update Bounds:
Note: BGrid iterates Latitude from North (90) to South (-90) (top-down in grid terms).
Final Result
The resulting bounds define the area covered by the BGrid address. The point coordinate is typically the center of these bounds.
6. String Representation
The numeric indices naturally map to the BIP39 wordlist, which contains 2048 words.
- Index 1 Word 1 (
abandon) - Index 2048 Word 2048 (
zoo)
This allows BGrid addresses to be localized into any language supported by BIP39.
Format
Standard text representation uses a designated separator (usually space or hyphen).
- Raw:
[4, 1827, 201] - Text (English):
ability-smoke-board