The weights of an area-weighted regrid: for every polygon of x and every grid cell it
overlaps, the area (km²) of their intersection. Built from exactextractr coverage
fractions (exact, sub-cell) times each cell's area on the WGS84 ellipsoid
(terra::cellSize(), latitude-dependent), over a window of the cell-id raster cropped to
x on the grid's OWN cell edges (snap = "out"), so the cell ids are the grid's.
Value
a tibble (poly_i integer, cell_id integer, area_km2 double, cell_km2 double), one
row per (polygon, cell) with positive overlap: poly_i is the row of x, area_km2 the
overlap area and cell_km2 the whole cell's area. Cells whose id is NA are dropped.
Details
The table depends on geometry only, so one call serves every layer that shares it (the
13 SWFSC CCE species carry identical 0.1° cells); pass it to cells_area_mean() once per
layer. Coverage is planar within a cell (a 0.05° cell's area varies by < 0.01 % across its
height), so area_km2 is exact to that order.
Examples
if (FALSE) { # \dontrun{
w <- poly_cell_overlap(ply_cells, cellid_tif) # once per geometry
d <- cells_area_mean(w, sf::st_drop_geometry(ply_cells)[c("DENSITY", "UNCERTAINTY")])
} # }