
Unify per-WSG barrier sources into the working-schema <schema>.barriers
Source: R/lnk_barriers_unify.R
lnk_barriers_unify.RdConsolidates four barrier families from the per-WSG working schema
(<schema>.crossings, <schema>.gradient_barriers_raw, <schema>.falls,
<schema>.barriers_subsurfaceflow) into one <schema>.barriers
table matching the cols_barriers shape used by the persistent
province-wide <persist_schema>.barriers. Each row carries a
pre-computed blocks_species text[] predicate that
lnk_pipeline_access() queries via WHERE 'BT' = ANY(blocks_species).
Arguments
- conn
A DBI connection.
- aoi
Watershed group code, e.g.
"PARS".- cfg
An
lnk_configobject.- loaded
Named list from
lnk_load_overrides(). Must includeloaded$parameters_fresh(used to derive gradient-classblocks_species).- schema
Working schema name (per-WSG staging). Default
paste0("working_", tolower(aoi)).- species
Character vector of species codes whose access thresholds drive the gradient
blocks_speciesderivation. Defaultunique(loaded$parameters_fresh$species_code). Pass a subset (e.g. the 8 bcfp species) to control which species the gradient blocks_species column references.
Details
Per-WSG output is persisted to the province-wide table by
lnk_pipeline_persist() using the same idempotent DELETE-WHERE-WSG +
INSERT pattern already used for streams and
streams_habitat_<sp>. Cross-WSG dam_dnstr_ind resolves correctly
because fresh::frs_network_features() walks FWA topology and
doesn't care which WSG a barrier physically lives in — fixes the
PARS BT 60% defect (PARS drains through dams in PCEA/UPCE WSGs)
and unblocks any regional run.
Source families + blocks_species semantics:
Anthropogenic (
barrier_source IN ('PSCIS','CABD','MODELLED_CROSSINGS'), from<schema>.crossings WHERE barrier_status IN ('BARRIER','POTENTIAL')): blocks all 8 species.crossing_sourceis mapped through verbatim, keeping theMODELLED_CROSSINGSvalue (vs. lossy normalization toMODELLED).Gradient (
barrier_source = 'GRADIENT', from<schema>.gradient_barriers_raw): blocks species whoseaccess_gradient_max <= gradient_class / 100. Derived per row fromloaded$parameters_fresh.Falls (
barrier_source = 'FALLS', from<schema>.falls): blocks all 8 species.Subsurface_flow (
barrier_source = 'SUBSURFACE_FLOW', from<schema>.barriers_subsurfaceflow): blocks all 8 species. Opt-in (only built whencfg$pipeline$break_orderincludes"subsurfaceflow").User_definite (
barrier_source = 'USER_DEFINITE', from<schema>.barriers_definite): blocks all 8 species. ltrees +linear_feature_idresolved by JOIN towhse_basemapping.fwa_stream_networks_sp(mirrors the FALLS branch and bcfp'sbarriers_user_definite.sql). Persisted province-wide so the per-species access view (barriers_<sp>_access,lnk_barriers_views()) can include them override-exempt — link#200.
Remediations (PASSABLE remediation crossings) are intentionally NOT
in this table. They're consumed via <schema>.barriers_remediations
(emitted by lnk_barriers_emit()) for the remediated_dnstr_ind
sequence-aware logic in lnk_pipeline_access(), which joins to
<schema>.crossings directly.
id_barrier is namespaced per source family so rows stay unique
inside a WSG without coordinating sequence IDs across sources.
Mirrors the offset trick .lnk_crossings_union uses for modelled
crossings.
Required pre-existing tables in schema:
<schema>.crossings(fromlnk_pipeline_crossings()).<schema>.gradient_barriers_raw(fromlnk_pipeline_prepare()).<schema>.falls(fromlnk_pipeline_prepare()).<schema>.barriers_definite(fromlnk_pipeline_prepare(); always created, may be empty).
Optional:
<schema>.barriers_subsurfaceflow(only when the config opts in).
Examples
if (FALSE) { # \dontrun{
conn <- lnk_db_conn()
cfg <- lnk_config("bcfishpass")
loaded <- lnk_load_overrides(cfg)
lnk_pipeline_setup(conn, schema = "working_pars")
lnk_pipeline_load(conn, "PARS", cfg, loaded, "working_pars")
lnk_pipeline_prepare(conn, "PARS", cfg, loaded, "working_pars",
conn_tunnel = conn)
lnk_pipeline_crossings(conn, "PARS", cfg, loaded, "working_pars")
lnk_barriers_unify(conn, aoi = "PARS", cfg = cfg, loaded = loaded,
schema = "working_pars")
DBI::dbReadTable(conn, c("working_pars", "barriers"))
} # }