
Snap HYDAT stations to FWA fundamental watersheds, checked by drainage area
Source:R/wet_station_snap.R
wet_station_snap.RdFinds the num_features nearest streams to each station with fwapg's
fwa_indexpoint(), in one query for all stations, and keeps the candidate
whose upstream area is closest to HYDAT's gross drainage area on a log
scale. The nearest
segment at a confluence is often the wrong stream, and the area is what
tells them apart. A snap is accepted when that area is within max_dev of
the gross drainage area.
Usage
wet_station_snap(
conn,
stations,
tolerance = 1000,
num_features = 5,
max_dev = 0.1,
lake_dist = 3000,
lake_min_ha = 100,
lake_min_share = 0.5
)Arguments
- conn
A DBI connection to an fwapg database.
- stations
data.frame(station_number, lon, lat, drainage_area_gross_km2), e.g. fromwet_station_select().- tolerance
Search distance, m.
- num_features
Candidates per station.
- max_dev
Accepted relative deviation of the snapped area from the gross drainage area.
A station is flagged as a lake outlet when a lake of at least
lake_min_hahectares lies withinlake_distmetres of the gauge, has stream segments upstream of the snapped point on the FWA network (fwa_upstream()), and drains betweenlake_min_shareand1 + max_devof the gauge's upstream area. So an inlet, an off-network pond, or a lake on a tributary is not one; the upper bound also catches an inlet that an FWA coding fault places upstream.
Value
data.frame(station_number, linear_feature_id, watershed_feature_id, wscode, localcode, distance_m, upstream_area_km2, area_ratio, accepted, reason, lake), one row per station. Stations with no candidate keep a
row with accepted = FALSE.
Details
fwa_indexpoint() returns one candidate per stream, its nearest point, so
the choice is between streams. fresh::frs_point_snap() lists candidates
per segment, several of which can lie on one stream, so it is not used here.
Upstream area here is fwapg's stored fwa_watersheds_upstream_area, which
is good enough to choose between candidates. The area the water balance
compares against is accumulated later from the live polygons.