Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/program--/hilbert

R :package: for Hilbert Curve indexing of coordinates
https://github.com/program--/hilbert

hilbert-curve r spatial

Last synced: 24 days ago
JSON representation

R :package: for Hilbert Curve indexing of coordinates

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

[![CRAN status](https://www.r-pkg.org/badges/version/hilbert)](https://CRAN.R-project.org/package=hilbert)
[![Codecov test coverage](https://codecov.io/gh/program--/hilbert/branch/main/graph/badge.svg)](https://app.codecov.io/gh/program--/hilbert?branch=main)
[![R-CMD-check](https://github.com/program--/hilbert/workflows/R-CMD-check/badge.svg)](https://github.com/program--/hilbert/actions)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](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
```