Skip to contents

Fast lookup of the cells making up a Program Area by reading directly from the zone / zone_cell tables. Returns the same shape (cell_id, pct_covered) as cells_in_polygon() so downstream helpers consume the two interchangeably.

Usage

cells_in_pra(con, pra_key)

Arguments

con

a DBI connection (e.g. from sdm_db_con())

pra_key

Program Area key (e.g. "CGM")

Value

tibble(cell_id integer, pct_covered numeric 1-100)

Details

pct_covered is the stored coverage, not 100. zone_cell membership is not binary: it holds the exactextractr coverage fraction x 100, and 74,938 of 2,241,876 rows are partial. This function used to overwrite all of them with 100L, so a single report weighted its Program-Area scores by coverage (via the precomputed zone_metric) while weighting the species table of the same area uniformly — the edge cells of every coastal area counted for more species than they contributed area. test-calc.R keeps that as a named regression.

The zone key column is resolved with sdm_val_col(): v1-v7 spell it value, v8+ val, and a served v8 view carries both. Hardcoding value made this function work on every served release and fail on a v8/v9 source database.