
Index Upstream/Downstream Features for Stream Segments
Source:R/frs_feature_index.R
frs_feature_index.RdFor each segment in a stream table, find which features from a feature table are upstream or downstream on the network. Stores results as feature ID arrays — enabling queries like "which crossings are between this segment and the ocean?"
Usage
frs_feature_index(
conn,
segments,
features,
direction = "downstream",
col_segment_id = "id_segment",
col_feature_id = "feature_id",
to = "working.feature_index",
label_filter = NULL,
overwrite = TRUE,
verbose = TRUE
)Arguments
- conn
A DBI::DBIConnection object.
- segments
Character. Schema-qualified segmented streams table (from
frs_network_segment()).- features
Character. Schema-qualified feature table (from
frs_feature_find()).- direction
Character.
"downstream"(features between segment and ocean) or"upstream"(features above segment). Default"downstream".- col_segment_id
Character. Segment ID column. Default
"id_segment".- col_feature_id
Character. Feature ID column. Default
"feature_id". If the feature table has no ID column, uses row position.- to
Character. Output table name. Default
"working.feature_index".- label_filter
Character or
NULL. SQL predicate to filter features by label before indexing (e.g."label = 'blocked'").- overwrite
Logical. Drop
tobefore creating. DefaultTRUE.- verbose
Logical. Print progress. Default
TRUE.
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_habitat(),
frs_habitat_access(),
frs_habitat_classify(),
frs_habitat_overlay(),
frs_habitat_partition(),
frs_habitat_predicates(),
frs_habitat_species(),
frs_network_segment()
Examples
if (FALSE) { # \dontrun{
conn <- frs_db_conn()
# Which crossings are downstream of each segment?
frs_feature_index(conn,
segments = "fresh.streams",
features = "working.features_crossings",
direction = "downstream",
to = "working.crossings_dnstr")
# Query: segments with confirmed barriers downstream
DBI::dbGetQuery(conn, "
SELECT s.id_segment, i.features_dnstr
FROM fresh.streams s
JOIN working.crossings_dnstr i ON s.id_segment = i.id_segment
WHERE array_length(i.features_dnstr, 1) > 0
LIMIT 10")
# Fish observations upstream of each segment
frs_feature_index(conn,
segments = "fresh.streams",
features = "working.features_fish_obs",
direction = "upstream",
col_feature_id = "fish_observation_point_id",
to = "working.fish_obs_upstr")
DBI::dbDisconnect(conn)
} # }