if (require(plm, quietly = TRUE)) {
data(Produc, package = "plm")
st_as_stars(Produc)
}
if (require(dplyr, quietly = TRUE)) {
# https://stackoverflow.com/questions/77368957/
spatial_dim <- st_sf(
ID = 1:3,
geometry = list(
st_polygon(list(
cbind(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0))
)),
st_polygon(list(
cbind(c(1, 2, 2, 1, 1), c(0, 0, 1, 1, 0))
)),
st_polygon(list(
cbind(c(2, 3, 3, 2, 2), c(0, 0, 1, 1, 0))
))
)
)
weekdays_dim <- data.frame(weekdays = c("Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday"))
hours_dim <- data.frame(hours = c("8am", "11am", "4pm", "11pm"))
sf_dta <- spatial_dim |>
cross_join(weekdays_dim)|>
cross_join(hours_dim) |>
mutate(population = rnorm(n(), mean = 1000, sd = 200)) |>
select(everything(), geometry)
st_as_stars(sf_dta, dims = c("weekdays", "hours", "geometry"))
}
demo(nc, echo=FALSE,ask=FALSE)
st_as_stars(nc)
st_as_stars(st_drop_geometry(nc), dims = "NAME")
data.frame(expand.grid(x=1:5, y = 1:5), z = rnorm(25)) |> st_as_stars()
nc = st_read(system.file("gpkg/nc.gpkg", package="sf"))
st_as_stars(nc)
Run the code above in your browser using DataLab