Open vecchiocarmelo opened 8 years ago
hash2latlonbbox <- function(hash,precision=7){
library(geohash)
evenLevelCorner <- matrix(c('b','0','z','p'),2,2) oddLevelCorner <- matrix(c('p','0','z','b'),2,2)
hashBbox <- matrix(rep(hash,4),2,2) # variable holding has of the corner boxes of the original hash box lengthHash <- nchar(hash)
if(lengthHash >= precision) precision <- lengthHash+2 # to provide good enough long lat resolution within m
nrOfBoxing <- precision - lengthHash
for(i in 1:nrOfBoxing) # loop for sub-dividing into smaller hash boxes if(length(hashBbox[1]) %% 2 == 1){ #odd length of hash hashBbox <- matrix(paste(hashBbox,oddLevelCorner,sep=''),2,2)
}else{ # even length of hash
hashBbox <- matrix(paste(hashBbox,evenLevelCorner,sep=''),2,2)
}
return(gh_decode(hashBbox)) #conversion of hash into lat &lon }
Thanks; I imagine the goal is to implement it in C++, but we'll see how it works.
@Ironholds I've made a PR: https://github.com/Ironholds/geohash/pull/19
It will be very useful given a geohash to have a function that return the bounding box (in lat,long)