https://github.com/program--/hilbert
R :package: for Hilbert Curve indexing of coordinates
https://github.com/program--/hilbert
hilbert-curve r spatial
Last synced: 9 months ago
JSON representation
R :package: for Hilbert Curve indexing of coordinates
- Host: GitHub
- URL: https://github.com/program--/hilbert
- Owner: program--
- License: other
- Created: 2022-03-09T17:43:48.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-08T15:31:34.000Z (almost 4 years ago)
- Last Synced: 2025-04-13T09:06:46.840Z (9 months ago)
- Topics: hilbert-curve, r, spatial
- Language: R
- Homepage: https://hilbert.justinsingh.me
- Size: 1.55 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# hilbert
[](https://CRAN.R-project.org/package=hilbert)
[](https://app.codecov.io/gh/program--/hilbert?branch=main)
[](https://github.com/program--/hilbert/actions)
[](https://opensource.org/licenses/MIT)
**hilbert** provides utilities for quick indexing/encoding of coordinates to a Hilbert Curve.
## Installation
You can install **hilbert** via either `remotes` or `pak`:
``` r
# pak
pak::pkg_install("program--/hilbert")
# remotes
remotes::install_github("program--/hilbert")
```
## Example
### Setting Up
```{r setup}
x <- -77.85641
y <- 34.35935
n <- 24 # n > 15 requires `bit64`
e <- c(xmax = 180, xmin = -180, ymax = 90, ymin = -90)
```
### Coordinates to Position
```{r coords2pos}
pos <- hilbert::coords_to_position(x, y, n = n, extent = e)
pos
```
### Position to Index
```{r pos2index}
index <- hilbert::index(pos, coords = c("x", "y"), n = n, attach = TRUE)
index
```
### Index to Position
```{r index2pos}
new_pos <- hilbert::position(index, idx = "h", n = n, attach = FALSE)
new_pos
```
### Position to Coordinates
```{r pos2coords}
new_xy <- hilbert::position_to_coords(new_pos, coords = c("x", "y"), extent = e, n = n, attach = TRUE)
new_xy
```