Title: Coordinate Indexing on Hilbert Curves
Version: 0.2.1
Description: Provides utilities for encoding and decoding coordinates to/from Hilbert curves based on the iterative encoding implementation described in Chen et al. (2006) <doi:10.1002/spe.793>.
URL: https://hilbert.justinsingh.me, https://github.com/program--/hilbert
BugReports: https://github.com/program--/hilbert/issues
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.1.2
SystemRequirements: C++11
Suggests: bit64 (≥ 4.0.0), testthat (≥ 3.0.0), covr, knitr, rmarkdown
LinkingTo: cpp11
Config/testthat/edition: 3
VignetteBuilder: knitr
NeedsCompilation: yes
Packaged: 2022-04-06 17:51:25 UTC; jsinghm
Author: Justin Singh-Mohudpur ORCID iD [aut, cre]
Maintainer: Justin Singh-Mohudpur <justin@justinsingh.me>
Repository: CRAN
Date/Publication: 2022-04-08 08:42:30 UTC

Convert Coordinates to Grid Positions

Description

Convert Coordinates to Grid Positions

Usage

coords_to_position(x, ..., n = 10L, extent = NULL)

## S3 method for class 'data.frame'
coords_to_position(x, ..., n, extent, coords = c(1, 2), attach = TRUE)

## S3 method for class 'matrix'
coords_to_position(x, ..., n, extent, coords = c(1, 2), attach = TRUE)

## S3 method for class 'numeric'
coords_to_position(x, y, ..., n, extent)

## S3 method for class 'double'
coords_to_position(x, y, ..., n, extent)

## S3 method for class 'integer'
coords_to_position(x, y, ..., n, extent)

coords_to_position64(x, ..., n = 10L, extent = NULL)

## S3 method for class 'data.frame'
coords_to_position64(x, ..., n, extent, coords = c(1, 2), attach = TRUE)

## S3 method for class 'matrix'
coords_to_position64(x, ..., n, extent, coords = c(1, 2), attach = TRUE)

## S3 method for class 'numeric'
coords_to_position64(x, y, ..., n, extent)

## S3 method for class 'double'
coords_to_position64(x, y, ..., n, extent)

## S3 method for class 'integer'
coords_to_position64(x, y, ..., n, extent)

Arguments

x

One of: Numeric vector, data.frame, or matrix. If a numeric vector, then it corresponds to X coordinates.

...

Unused.

n

Exponent to the dimensions of the underlying grid. The Hilbert Curve indices are based on a ⁠2^n x 2^n⁠ grid. This number must be less than 15 due to the 32-bit implementation of R.

extent

Named vector with names xmax, xmin, ymax, ymin. Corresponds to the bounding box of the given coordinates. If extent is NULL, then the bounding box is found from the given coordinates.

coords

Column names or indices of a data.frame/matrix that contain the coordinates.

attach

If TRUE, adds the position as new columns to the given data.frame/matrix. This will replace the coordinate columns.

y

Numeric vector corresponding to Y coordinates.

Value

A data.frame containing the positions as integer columns x and y, or the original object (data.frame or matrix) with the coordinates replaced with the grid positions. When n is greater than 15, the positions are of type bit64::integer64.


Index positions to a Hilbert Curve

Description

Index positions to a Hilbert Curve

Usage

index(x, ..., n = 10L)

## S3 method for class 'data.frame'
index(x, ..., n, coords = c(1, 2), attach = TRUE)

## S3 method for class 'matrix'
index(x, ..., n, coords = c(1, 2), attach = TRUE)

## S3 method for class 'double'
index(x, y, ..., n)

## S3 method for class 'numeric'
index(x, y, ..., n)

## S3 method for class 'integer'
index(x, y, ..., n)

index64(x, ..., n = 10L)

## S3 method for class 'data.frame'
index64(x, ..., n, coords = c(1, 2), attach = TRUE)

## S3 method for class 'matrix'
index64(x, ..., n, coords = c(1, 2), attach = TRUE)

## S3 method for class 'double'
index64(x, y, ..., n)

## S3 method for class 'integer'
index64(x, y, ..., n)

## S3 method for class 'numeric'
index64(x, y, ..., n)

## S3 method for class 'integer64'
index64(x, y, ..., n)

## S3 method for class 'character'
index64(x, y, ..., n)

## S3 method for class 'bitstring'
index64(x, y, ..., n)

Arguments

x

One of: Numeric vector, data.frame, or matrix. If a numeric vector, then it corresponds to the rows of a position.

...

Unused.

n

Exponent to the dimensions of the underlying grid. The Hilbert Curve indices are based on a ⁠2^n x 2^n⁠ grid. This number must be less than 15 due to the 32-bit implementation of R.

coords

Column names or indices of a data.frame/matrix that contain the position coordinates.

attach

If TRUE, adds the indices as a new column to the given data.frame/matrix. If x is a data.frame, then the column is named h; otherwise, it is an unnamed column at the end of the matrix.

y

Numeric vector. Corresponds to the columns of a position.

Value

An integer vector of Hilbert indices, or when attach is TRUE, the original object (data.frame or matrix) with a new integer column (h for data.frame) containing the Hilbert indices. When n is greater than 15, the vector is of type bit64::integer64.


Get index positions from a Hilbert Curve

Description

Get index positions from a Hilbert Curve

Usage

position(h, ..., n = 10L)

## S3 method for class 'data.frame'
position(h, ..., n, idx = 1, attach = TRUE)

## S3 method for class 'matrix'
position(h, ..., n, idx = 1, attach = TRUE)

## S3 method for class 'numeric'
position(h, ..., n)

## S3 method for class 'integer'
position(h, ..., n)

position64(h, ..., n = 10L)

## S3 method for class 'data.frame'
position64(h, ..., n, idx = 1, attach = TRUE)

## S3 method for class 'matrix'
position64(h, ..., n, idx = 1, attach = TRUE)

## S3 method for class 'double'
position64(h, ..., n)

## S3 method for class 'integer'
position64(h, ..., n)

## S3 method for class 'numeric'
position64(h, ..., n)

## S3 method for class 'integer64'
position64(h, ..., n)

## S3 method for class 'character'
position64(h, ..., n)

## S3 method for class 'bitstring'
position64(h, ..., n)

Arguments

h

One of: Integer vector, data.frame, or matrix.

...

Unused.

n

Exponent to the dimensions of the underlying grid. The Hilbert Curve indices are based on a ⁠2^n x 2^n⁠ grid. This number must be less than 15 due to the 32-bit implementation of R. This must be the same as the n used in index.

idx

Column name or index containing the Hilbert Curve indices.

attach

If TRUE, adds the position as new columns to the given data.frame/matrix. If h is a data.frame, then the columns are named x and y; otherwise, it is two unnamed columns at the end of the matrix.

Value

A data.frame containing the positions as integer columns x and y, or the original object (data.frame or matrix) with the columns attached. When n is greater than 15, the positions are of type bit64::integer64.


Convert Grid Positions to Coordinates

Description

Convert Grid Positions to Coordinates

Usage

position_to_coords(x, ..., n = 10L, extent = NULL)

## S3 method for class 'data.frame'
position_to_coords(x, ..., n, extent, coords = c(1, 2), attach = TRUE)

## S3 method for class 'matrix'
position_to_coords(x, ..., n, extent, coords = c(1, 2), attach = TRUE)

## S3 method for class 'numeric'
position_to_coords(x, y, ..., n, extent)

## S3 method for class 'double'
position_to_coords(x, y, ..., n, extent)

## S3 method for class 'integer'
position_to_coords(x, y, ..., n, extent)

position_to_coords64(x, ..., n = 10L, extent = NULL)

## S3 method for class 'data.frame'
position_to_coords64(x, ..., n, extent, coords = c(1, 2), attach = TRUE)

## S3 method for class 'matrix'
position_to_coords64(x, ..., n, extent, coords = c(1, 2), attach = TRUE)

## S3 method for class 'numeric'
position_to_coords64(x, y, ..., n, extent)

## S3 method for class 'double'
position_to_coords64(x, y, ..., n, extent)

## S3 method for class 'integer64'
position_to_coords64(x, y, ..., n, extent)

## S3 method for class 'bitstring'
position_to_coords64(x, y, ..., n, extent)

Arguments

x

One of: Integer vector, data.frame, or matrix. If a numeric vector, then it corresponds to Row positions.

...

Unused.

n

Exponent to the dimensions of the underlying grid. The Hilbert Curve indices are based on a ⁠2^n x 2^n⁠ grid. This number must be less than 15 due to the 32-bit implementation of R.

extent

Named vector with names xmax, xmin, ymax, ymin. Corresponds to the bounding box of the given coordinates. If extent is NULL, then the function will throw an exception.

coords

Column names or indices of a data.frame/matrix that contain the positions.

attach

If TRUE, adds the coordinates as new columns to the given data.frame/matrix. This will replace the position columns.

y

Integer vector corresponding to Column positions.

Value

A data.frame containing the coordinates as numeric columns x and y, or the original object (data.frame or matrix) with the positions replaced with the coordinates.