inst/doc/a5R.R

## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(a5R)

## -----------------------------------------------------------------------------
cell <- a5_lonlat_to_cell(-3.19, 55.95, resolution = 10)
cell

## -----------------------------------------------------------------------------
a5_cell_to_lonlat(cell)

## ----boundary-plot, fig.width = 5, fig.height = 4-----------------------------
boundary <- a5_cell_to_boundary(cell)
boundary

plot(boundary, col = "#206ead20", border = "#206ead", asp = 1)

## -----------------------------------------------------------------------------
parent <- a5_cell_to_parent(cell)
parent

children <- a5_cell_to_children(cell)
children

## ----hierarchy-plot, fig.width = 8, fig.height = 8----------------------------
plot(NULL, xlim = c(-3.23, -3),  ylim = c(55.98, 55.99),               
       xlab = "", ylab = "", asp = 1
       )
plot(a5_cell_to_boundary(a5_cell_to_children(cell)),
     col = "#ad6e2020", border = "#ad6e20", add = TRUE)
plot(a5_cell_to_boundary(cell), col = "#206ead40", border = "#206ead",
     lwd = 2, add = TRUE)
plot(a5_cell_to_boundary(parent), border = "#333333", lwd = 2, add = TRUE)

## -----------------------------------------------------------------------------
a5_cell_area(0:5)

## -----------------------------------------------------------------------------
children
a5_compact(children)

# round-trips back to the original
a5_uncompact(a5_compact(children), resolution = 11)

## ----traversal, fig.width = 7-------------------------------------------------
disk <- a5_grid_disk(cell, k = 10)
cap <- a5_spherical_cap(cell, radius = 50000)

plot(a5_cell_to_boundary(cap), col = "#6ead2020", border = "#6ead20", asp = 1)
plot(a5_cell_to_boundary(disk), col = "#206ead20", border = "#206ead", asp = 1)

## ----traversal-uncompact, fig.width = 7---------------------------------------
disk_grid <- a5_uncompact(disk, resolution = a5_get_resolution(cell))

plot(a5_cell_to_boundary(disk_grid), col = "#206ead20", border = "#206ead", asp = 1)

## ----grid-plot, fig.width = 7-------------------------------------------------
cells <- a5_grid(c(-3.3, 55.9, -3.1, 56.0), resolution = 12)
length(cells)

plot(a5_cell_to_boundary(cells), col = "#206ead20", border = "#206ead", asp = 1)

## ----eval = requireNamespace("sf", quietly = TRUE)----------------------------
library(sf)
demo(nc, ask = FALSE, echo = FALSE)
nca5 <- a5_grid(nc, resolution = 9)
plot(a5_cell_to_boundary(nca5), col = "#6d20ad20", border = "#6d20adff", asp = 1)

Try the a5R package in your browser

Any scripts or data that you put into this service are public.

a5R documentation built on March 26, 2026, 5:10 p.m.