A s2cd vector (short for s2_cell_dates)
stores an s2::s2_cell vector alongside a list of date vectors,
where each vector of chronologically, non-missing dates corresponds to each
valid, level 30 s2 cell. Create a new s2cd vector with s2cd() or coerce
another object into a s2cd vector with as_s2cd().
Usage
s2cd(.data, dates = list(), sort_dates = FALSE)Details
Each position in the s2_cells vector corresponds to the same-indexed element in dates, allowing multiple dates to be associated with a single level-30 S2 cell.
At level 30, S2 cells have an approximate spatial resolution of 1 centimeter; in this context, they are intended to function as point-like representations rather than true spatial areas.
Examples
# create directly with s2_cell vector and list of Date vectors
d <- s2cd(
s2::as_s2_cell(c("8841b39a7c46e25f", "8841a45555555555")),
dates = list(
as.Date("2026-01-01"),
c(as.Date("2024-09-13"), as.Date("2024-09-20"))
)
)
# check if d is a s2cd vector
is_s2cd(d)
#> [1] TRUE
# use a s2cd vector as a tibble column
# the display includes each cell's number of dates
tibble::tibble(id = seq_along(d), location = d)
#> # A tibble: 2 × 2
#> id location
#> <int> <s2cd>
#> 1 1 8841b39a7c46e25f[1]
#> 2 2 8841a45555555555[2]
# create using data.frame with s2_cell and dates columns
data.frame(
s2_cell = s2::as_s2_cell(c("8841b39a7c46e25f", "8841a45555555555")),
dates = I(list(
as.Date("2026-01-01"),
c(as.Date("2024-09-13"), as.Date("2024-09-20"))
))
) |>
as_s2cd()
#> <s2_cell_dates[2]>
#> [1] 8841b39a7c46e25f[1] 8841a45555555555[2]