geo-hash
GeoHash implementation
Geohash converts point into hash that can uniquely identify cell on the map of the world Hash length will determines size of the cell with following table illustrating approximate sizes
| Hash Len | Width | Height |
|---|---|---|
| 1 | <=5km | 5km |
| 2 | <=1.250km | 625km |
| 3 | <=156km | 156km |
| 4 | <=39.1km | 19.5km |
| 5 | <=4.89km | 4.89km |
| 6 | <=1.22km | 0.61km |
| 7 | <=153m | 153m |
| 8 | <=38.2m | 19.1m |
| 9 | <=4.77m | 4.77m |
| 10 | <=1.19m | 0.596m |
| 11 | <=149mm | 149mm |
| 12 | <=37.2mm | 18.6mm |
Note, width becomes smaller depending on how far coordinate is from equator
The important property of the resulting hash is that the closer coordinates are, the bigger common prefix is between two hashes.
Features
serde - Implements serde interface on GeoHash
Usage
Encode with static hash size
You can use Codec to ensure encoding will never fail at compile time by supplying it with
length of the hash you desire
use Coordinate;
type CODEC = ;
let position = try_new.expect;
let hash = CODECencode;
assert_eq!;
Encode with dynamic hash size
You can use GeoHash::encode when you cannot know size of the hash at compile time, which will fail if hash length is not within range of 1..=12
use ;
let position = try_new.expect;
let hash = encode.expect;
assert_eq!;
Decode hash to determine approximate position
When you only have textual hash, you can determine its bounding box or as approximation position within this bounding box
use ;
const COORD: Coordinate = new;
//This function only checks length
let hash = try_from_str.expect;
assert_eq!;
//This function will check validity of hash itself
let bbox = hash.decode_bbox.expect;
assert_eq!;
assert_eq!;
let position = bbox.position;
assert_eq!;