hilbert provides utilities for quick indexing/encoding of coordinates to a Hilbert Curve.
You can install hilbert via either remotes
or pak
:
x <- -77.85641
y <- 34.35935
n <- 24 # n > 15 requires `bit64`
e <- c(xmax = 180, xmin = -180, ymax = 90, ymin = -90)
index <- hilbert::index(pos, coords = c("x", "y"), n = n, attach = TRUE)
index
#> x y h
#> 1 4760236 11591131 129470580596149
new_pos <- hilbert::position(index, idx = "h", n = n, attach = FALSE)
new_pos
#> x y
#> 1 4760236 11591131