Build the shared grid reference table (deterministic, dataset-independent)
Source: R/model.R
build_grid_reference.RdMaterializes the CalCOFI station grid from calcofi4r::cc_grid +
calcofi4r::cc_grid_ctrs — the exact build embedded in ingest_swfsc_ichthyo.qmd
(mk_grid_v2 + grid_to_db), which is what writes the released grid. Because it
is a pure deterministic function of the bundled cc_grid/cc_grid_ctrs, grid_key
values are byte-identical wherever it runs. Requires the DuckDB connection to allow
native GEOMETRY (open via get_duckdb_con(), which sets
storage_compatibility_version = 'latest').
Usage
build_grid_reference(
con,
grid_tbl = "grid",
cc_grid = calcofi4r::cc_grid,
cc_grid_ctrs = calcofi4r::cc_grid_ctrs
)Details
The grid is whatever cc_grid is: from calcofi4r 1.25.0, one cell per official station (a
Voronoi tessellation of the official station positions, confined to the previous cells it
replaces) beside the previous cells beyond the official pattern, kept as they were
(CalCOFI/workflows#130); before it, the idealized lattice (cc_grid_v1). The columns are the same either way:
grid_key (st{station}-ln{line}, _hist for the historical pattern), station,
line, shore, pattern, spacing, zone, area_km2, geom (a polygon, or a
multipolygon for a cell in several pieces) and geom_ctr (the cell's site: the station
itself in the rebuilt grid, the centroid of the cell's largest polygon before). Where cc_grid carries its own grid_key, the key derived here must
equal it, and the build stops otherwise. The two grids share key names whose polygons
differ; build_grid_crosswalk() maps one to the other.