Returns cell_id + pct_covered (0-100) for the cells a polygon overlaps.
pct_covered is the fraction of each cell inside the polygon, and it is not
cosmetic — scores_for_cells() and species_for_cells() weight by it, so
partially covered edge cells count proportionally.
Arguments
- poly
an sf polygon (assumed or transformable to EPSG:4326)
- src
a DBI connection (preferred), or a single-layer
terra::SpatRasterof integer cell ids- res
grid resolution in degrees, SQL path only (default
0.05)
Details
Pass a DB connection. Then the grid is read from the database being queried and cannot disagree with it. Two paths, chosen automatically:
v8 (
cellcarrieslon/lat) — a SQL bbox select oncellpicks the candidates andsfcomputes exact coverage on just those. No raster is touched. For a 2x1.5-degree area this is ~0.02 s against ~35 s to read the whole cell-id raster, and it joinscell_model, which is already cell-oriented.v7 (no
lon/lat) — falls back tocell_id_raster(), the 0-360 regional raster that IS v7's grid.
Passing a terra::SpatRaster directly still works, but nothing can then
verify it matches the database — see cell_id_raster() for how that failed
silently on v8.