| extract_panel | R Documentation |
Takes a named list of SpatRaster objects (one per time period, as returned by
ntl_download() or bhuvan_raster()) and an sf or SpatVector polygon
layer, and returns a tidy long-format data frame with one row per region and
time period. Annual names such as "2025" produce the original four-column
output. ISO-date names used by monthly and daily Black Marble additionally
produce a date column.
extract_panel(rasters, polygons, fun = "mean", id_col = NULL)
rasters |
A named list of |
polygons |
An |
fun |
Aggregation function name passed to |
id_col |
Name of the column in |
The polygons argument accepts any sf object: GADM, bharatviz GeoJSONs,
LGD districts, or any shapefile loaded with sf::read_sf().
A data frame with columns:
Character. Region identifier from polygons.
Integer. Year, taken from the name of each raster.
Numeric. Aggregated radiance value.
Integer. Number of non-NA cells contributing to the stat.
r <- terra::rast(
nrows = 10, ncols = 10, xmin = 0, xmax = 10, ymin = 0, ymax = 10,
crs = "EPSG:4326", vals = 1:100
)
rasters <- list("2020" = r, "2021" = r * 2)
square <- function(x0) {
sf::st_polygon(list(cbind(c(x0, x0 + 5, x0 + 5, x0, x0), c(0, 0, 10, 10, 0))))
}
regions <- sf::st_sf(
region = c("west", "east"),
geometry = sf::st_sfc(square(0), square(5), crs = 4326)
)
extract_panel(rasters, regions, id_col = "region")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.