
Build SQL predicates for one species' habitat classification
Source:R/frs_habitat_predicates.R
frs_habitat_predicates.RdPure-R helper: takes one species' rules + ranges from
frs_habitat_species() and returns a named list of SQL boolean
expressions ("predicates") — the raw yes/no questions that
frs_habitat_classify() embeds in CASE WHEN <pred> THEN TRUE ...
to produce the per-species habitat columns.
Arguments
- sp_params
A single-species params list as produced by one element of
frs_habitat_species(). Must containspecies_code,spawn_gradient_min,spawn_gradient_max,ranges, optionallyrules, optionallyspawn_edge_types/rear_edge_types.
Value
A named list with four character scalars: spawn, rear,
lake_rear, wetland_rear. Each is an SQL boolean expression
suitable for embedding in CASE WHEN ... THEN TRUE ELSE FALSE END. Predicates reference the segmented streams alias s..
Details
Returns four predicates per call: spawn, rear, lake_rear,
wetland_rear. Each is a fragment that references columns aliased
as s. (the segmented streams table). Caller is responsible for
embedding them in a complete query.
Two paths are supported, selected per habitat type by what's
present in sp_params:
Rules path — when
sp_params$rules$<spawn|rear>is non-NULL, the rules YAML is compiled to SQL via.frs_rules_to_sql(). CSV thresholds (gradient + channel_width) are passed as the inheritance fallback for rules that omit explicit thresholds.CSV-ranges path — pre-rules behaviour. Builds the SQL directly from
sp_params$ranges+sp_params$<spawn|rear>_edge_types.
Lake / wetland rearing predicates are gated on the presence of a
waterbody_type: L / waterbody_type: W rule in rear:. Without
the rule, the predicate is "FALSE" — the species is not lake or
wetland-rearing. With the rule, an optional lake_ha_min /
wetland_ha_min filters the polygon join.
Segments must still fall within the species' rear channel-width window for lake / wetland rearing.
See also
Other habitat:
frs_aggregate(),
frs_break(),
frs_break_apply(),
frs_break_find(),
frs_break_validate(),
frs_categorize(),
frs_classify(),
frs_cluster(),
frs_col_generate(),
frs_col_join(),
frs_extract(),
frs_feature_find(),
frs_feature_index(),
frs_habitat(),
frs_habitat_access(),
frs_habitat_classify(),
frs_habitat_overlay(),
frs_habitat_partition(),
frs_habitat_species(),
frs_network_segment()
Examples
if (FALSE) { # \dontrun{
params <- frs_params()
params_fresh <- read.csv(system.file("extdata",
"parameters_fresh.csv", package = "fresh"))
species_params <- frs_habitat_species("CO", params, params_fresh)
preds <- frs_habitat_predicates(species_params[[1]])
preds$spawn
#> "s.gradient >= 0 AND s.gradient <= 0.0549 AND ..."
preds$lake_rear
#> "FALSE" (CO has no waterbody_type: L rule under bcfishpass)
} # }