| Crates.io | n3gb-rs |
| lib.rs | n3gb-rs |
| version | 0.1.6 |
| created_at | 2025-12-06 21:11:25.301628+00 |
| updated_at | 2025-12-28 19:02:12.61103+00 |
| description | A Rust implementation of a hierarchical hex-based spatial indexing system based on the OSGB National Grid. |
| homepage | |
| repository | https://github.com/CHRISCARLON/n3gb-rs |
| max_upload_size | |
| id | 1970760 |
| size | 149,488 |
Rust implementation of a hex-based spatial indexing for British National Grid.
Inspired by the work done by GDS NUAR n3gb.
Creating a HexCell
Reconstructing from ID
How hex cells maintain the offset structure?
1. Single Cells - use HexCell
let point = Point::new(383640.0, 398260.0);
let cell = HexCell::from_bng(&point, 12)?;
println!("{}", cell.id);
let polygon = cell.to_polygon();
Example output:
Hex ID: AQAAAAAW3cpQAAAAABe831IMHg
Center: (383634, 398253.9062859271)
Row: 25548, Col: 21313
Polygon: POLYGON((383643.0 398259.1024383498,383634.0 398264.2985907725,383625.0 398259.1024383498,383625.0 398248.7101335044,383634.0 398243.5139810817,383643.0 398248.7101335044,383643.0 398259.1024383498))
2. Cell Collections - use HexGrid
let grid = HexGrid::builder()
.zoom_level(12)
.bng_extent(&(300000.0, 300000.0), &(350000.0, 350000.0))
.build();
if let Some(cell) = grid.get_cell_at(&point) {
println!("{}", cell.id);
}