MilesMcBain / slippymath

R functions for dealing with slippy map tile servers.
Other
65 stars 4 forks source link

Feature request: "quadkey" calculations #16

Open barryrowlingson opened 4 years ago

barryrowlingson commented 4 years ago

Feature Request

Some slippy map services (Bing maps in particular) use "quadkeys", a way of recursively partitioning the tile space. At the first zoom level, quadkey "0" is the top left tile, "1" is the top right, and "2" and "3" are the lower two. At the second zoom level, you add an extra digit to show which quarter of the higher level quarter you are in. So a quadkey of 112031 is zoom level 6. Details here https://docs.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system

I've seen a couple of questions asking about quadkeys on SO recently, and found a python library with computations for them, and wrote an R function in response. https://gis.stackexchange.com/questions/359507/how-to-convert-quadkey-into-tiles-coordinates/359636#359636

So now i can go from quadkey to lat-long using:

> t = quadkey_to_tile("12022132301033")
> slippymath::tilenum_to_lonlat(t$x, t$y, t$z)
$lon
[1] 9.382324

$lat
[1] 45.53714

Would this be suitable functionality for slippymath?