-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathREADME.Rmd
More file actions
75 lines (55 loc) · 2.4 KB
/
Copy pathREADME.Rmd
File metadata and controls
75 lines (55 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
output: github_document
---
# hfaggregate
`hfaggregate` provides utilities for collapsing high-resolution hydrofabrics
into analysis-ready outlet networks or uniform-sized catchment distributions.
It builds on the [`hfutils`](https://github.com/lynker-spatial/hfutils) toolkit
and expects standard Hydrofabric GeoPackages as inputs.
## Installation
```r
# install.packages("remotes")
remotes::install_github("lynker-spatial/hfaggregate", dependencies = TRUE)
```
The package imports `sf`, `terra`, `dplyr`, `hfutils`, and `cli`; make sure the
system requirements for those packages (GEOS, GDAL, PROJ) are available.
## Key functionality
- `aggregate_to_outlets()`: unions divides and mainstem flowpaths by outlet
groups discovered from POIs or critical levelpath junctions.
- `aggregate_to_distribution()`: enforces target catchment sizes while
respecting minimum flowpath length/area constraints and optional POI locks.
## Quick start
```{r, warning=FALSE, message=FALSE}
library(hfutils)
library(hfaggregate)
hf_path <- "/Users/mikejohnson/hydrofabric/hydrofabric-v3/tmp/rfc/nwis-06752260_rfc.gpkg"
pois <- hfutils::as_ogr(hf_path, "pois") |>
dplyr::select(flowpath_id, poi_id, geom) |>
hfutils::st_as_sf()
# Collapse the network around POI-constrained outlets
outlet_net <- aggregate_to_outlets(
gpkg = hf_path,
pois = pois
)
hfsubset::hfview(outlet_net) + pois
```
```{r, warning=FALSE, message=FALSE}
# Build a uniformly sized distribution
distribution <- aggregate_to_distribution(
gpkg = hf_path,
pois = pois
)
hfsubset::hfview(distribution) + pois
```
Both functions return lists with `flowpaths`, `divides`, and (optionally) `pois`
layers that can be written to disk via `hfutils::write_hydrofabric()`.
## Tuning aggregation behaviour
- **Outlets vs. POIs**: `aggregate_to_outlets()` seeds groups from the supplied
POIs; set `auto_seed_terminals = TRUE` inside `.partition_and_flag_mainstem()`
if you need terminal nodes treated as outlets even without POIs.
- **Size constraints**: `aggregate_to_distribution()` first merges along
mainstems (`aggregate_along_mainstems()`), then collapses headwaters via
`collapse_headwaters()`. Adjust `ideal_size_sqkm`, `min_length_km`, and
`min_area_sqkm` to bias the result toward longer or wider units.
- **POI preservation**: Provide an `sf` data frame with `flowpath_id` and
`poi_id` columns to prevent POI-bearing segments from being merged away.