hfutils provides the base utilities needed for hydrofabric I/O + navigation; geometry modification + cleaning; and authentication to the Lynker Spatial cloud. Collectively, it provides the building blocks from which reference fabrics and geoprocessed fabrics can be created.
Installation
You can install the development version of hfutils from GitHub with:
# install.packages("remotes")
remotes::install_github("lynker-spatial/hfutils")Basic Use
I/O
Basic connection: Dataset
# point this at a hydrofabric GeoPackage (with flowpaths + divides layers)
gpkg <- "reference_fabric.gpkg"
# With a single user layer, that layer is selected automatically. A source
# holding several layers is ambiguous, so as_ogr() lists them and asks you
# to name one.
hfutils::as_ogr(gpkg)
#> Error: Multiple layers found; please specify `layer` explicitly:
#> > divides, flowpathsBasic connection: Layer
hfutils::as_ogr(gpkg, "divides")Network Properties
## Accumulate Downstream
system.time({
da <- hfutils::as_ogr(gpkg, "flowpaths") |>
filter(vpuid == "01") |>
st_as_sf() |>
accumulate_downstream(attr = "areasqkm")
})
head(da)
## Hydrosequence
system.time({
hs <- hfutils::as_ogr(gpkg, "flowpaths") |>
filter(vpuid == "01") |>
st_as_sf() |>
get_hydroseq()
})
head(hs)