Triangular and Penta-Hexagonal Grids Based on Tessellated Icosahedra
icosa (originally εἴκοσι for twenty) refers to the icosahedron, the platonic solid with the highest number of faces. The ‘icosa’ extension is an implementation of icosahedral grids in three dimensions. The spherical-triangular tessellation can be set to create grids with custom resolutions. Both the primary triangular and their inverted penta-hexagonal grids can be calculated. Additional functions are provided that allow plotting of the grids and associated data, the interaction of the grids with other raster and vector objects, and treating the grids as a graphs.
These grids are often called icospheres, and have an important use in material design, architecture, computer graphics and chemistry.
Basic workflow
The workflow of icosa
uses a dedicated grid object that stores the spatial structure for grid cells or faces
. Although there is an in-development, dedicated object class to hold associated data (facelayer
-class), the simplest solution for working with associated data is to store it as named vectors, leveraging the power of base R programming.
library(icosa)
# create a grid (with ~10 degree distance between face centers)
hex <- hexagrid(spacing=10, sf=TRUE)
# grab some point data
# (this case: fossil occurrences from the Paleobiology Database)
library(divDyn) # another package on CRAN
data(corals, package="divDyn")
# the coordinates
coords <- corals[, c("lng", "lat")]
coords <- na.omit(coords)
# cell identifiers can be used in a general workflow
coords$cell<- locate(hex, coords)
# ... for instance in tabulation:
# What is the number of fossil occurrences in a cell?
nOccs <- table(coords$cell)
# visualization through sf
plot(hex, nOccs, logz=TRUE, border="white", reset=FALSE
main="Density of fossil scleractinian occurrences")
# putting a world map on it
ne <- sf::st_read(file.path(
system.file(package="icosa"),"extdata/ne_110m_land.shx" ), quiet=TRUE)
plot(ne$geometry, add=TRUE, col="#55555555", border=NA)
# The actual occurrences
points(coords, col="#00FF00", pch=3, cex=0.1)
Similar packages
Implementations of similar grids are available in R with the H3 library (h3-js) and the ddgridR libraries. These other implementations are based on hierarchical organizations of grid cells, which allows very high-resolution. In contrast, the icosa package was optimized for coarser resolutions, providing a more gradual change of cells sizes, more efficient 3D operations (e.g. grid rotation), and to be used in the R environment for spatially isotropic analysis - especially when it comes to latitudinal patterns. It allows access to not only hexagonal, but triangular grids as well.
Plans
- Finishing vignettes in Tutorials
- Paper about the package (long overdue)
- Moving internal vector-representation from
sp
tosf
- Customization of tesselation that allows tweaking of cell sizes and shapes - depending on needs
- Writing a C++ library from the core functionality and porting it to Python and Julia