n3gb-rs-0.1.2 has been yanked.
n3gb-rs
Rust implementation of a hex-based spatial indexing for British National Grid.
Inspired by the work done by GDS NUAR n3gb.
Simple Overview
Creating a HexCell
- point_to_hex — Takes your input coordinates and finds which grid cell they fall into. Returns (row, col).
- hex_to_point — Takes the (row, col) and calculates the exact center of that cell. This is where the offset for odd rows gets applied. Returns (center_x, center_y).
- generate_identifier — Takes the center coordinates of the HexCell and zoom level, packs it all into binary, and then encodes as Base64. The ID contains: version + center_x + center_y + zoom.
Reconstructing from ID
- decode_hex_identifier — Decodes the Base64 string back into version, center_x, center_y, and zoom.
- create_hexagon — Draws 6 vertices around the center at the radius for that zoom level.
How polygons maintain the offset structure?
- They don't care nor need to know about it.
- The offset is applied when hex_to_point calculates the centre.
- The centre coordinates themselves contain the offset.
Lib currently has two main entry points
1. Single Cells - use HexCell
let point = new;
let cell = from_bng?;
println!;
let polygon = cell.to_polygon;
Example output:
)
))
2. Cell Collections - use HexGrid
let grid = builder
.zoom_level
.bng_extent
.build;
if let Some = grid.get_cell_at