-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathREADME.Rmd
More file actions
77 lines (60 loc) · 3.54 KB
/
Copy pathREADME.Rmd
File metadata and controls
77 lines (60 loc) · 3.54 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
74
75
76
77
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
base_dir <- '/Users/mikejohnson/hydrofabric'
```
# hfsubset
<!-- badges: start -->
[](https://choosealicense.com/licenses/apache-2.0/)
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](#)
[](https://github.com/lynker-spatial/hfsubset/actions/workflows/pkgdown.yaml)
<!-- badges: end -->
`hfsubset` provides a lightweight, dependency-minimal subsetting utility for working with Lynker Spatial Hydrofabrics. It is designed to quickly extract spatial and network subsets of large hydrologic datasets, returning only the upstream or contributing features relevant to a specified location.
## Overview
The function operates on a Hydrofabric GeoPackage—a standardized container for vector-based hydrologic data layers (e.g., flowpaths, catchments, waterbodies). Given a reference point such as an NHDPlusV2 COMID (`comid`), Hydrofabric ID (`id`), or hydrolocation reference (`hl_reference`), it identifies and extracts all upstream features connected through the hydrologic network.
Each output layer is returned as an `sf` object containing only features contributing to the specified reference location. This structure makes it straightforward to visualize, analyze, or export targeted drainage areas without needing to process the full dataset.
An optional `outfile` parameter allows writing the subsetted layers back to a new GeoPackage (or any OGR spec for single layer calls) for persistent storage or sharing, or, if left NULL, allows the data to be returned in memory.
# Inputs
- **src**: Path to a local Hydrofabric GeoPackage/geoparquet (typically containing layers such as flowpaths, catchments, waterbodies, etc.)
> **reference**: A hydrologic location identifier. This can be either:
- `id`: A Hydrofabric ID
- `comid`: An NHDPlusV2 COMID
- `hl_reference`: A Hydrolocation reference (`hl_reference`). A hydrolocation reference (`hl_reference`) is a standardized string that encodes both the data source and the native identifier in the form: `{source}-{native_id}`
This convention allows `hfsubset` to resolve references across multiple hydrologic networks or catalog systems without ambiguity.
## Usage
```{r, warning=FALSE}
library(hfsubset)
library(mapview)
x <- hfsubset(src = glue::glue('{base_dir}/v3.0/reference_fabric.gpkg'),
hl_reference = "nwis-07187000")
lobstr::tree(x, max_depth = 1)
hfview(x)
```
```{r, warning=FALSE}
y <- hfsubset(src = glue::glue('{base_dir}/v3.0/refactored_fabric.gpkg'),
hl_reference = "nwis-07187000")
lobstr::tree(y, max_depth = 1)
hfview(y)
```
```{r, warning=FALSE}
z <- hfsubset(src = glue::glue('{base_dir}/CONUS/v2.2/nextgen/v2.2_conus.gpkg'),
hl_reference = "nwis-07187000")
lobstr::tree(z, max_depth = 1)
hfview(z)
```
```{r, warning=FALSE}
# hfutils::lynker_spatial_auth()
# hfsubset(src = "ls://3.0/superconus/reference",
# hl_reference = "nwis-07187000",
# lyrs = c("network", "flowpaths", "divides")) |>
# lobstr::tree(max_depth = 1)
```