Skip to contents

Retrieve and Process Vector Processing Unit (VPU) Hydrofabric Layers

This function retrieves and optionally filters spatial data layers from a GeoPackage (GPKG) based on a specified Vector Processing Unit ID (VPU ID). The function can either return the filtered layers as a list or write them to an output file.

Usage

get_vpu_fabric(gpkg, vpuid = NULL, outfile = NULL)

Arguments

gpkg

A string specifying the path to the GeoPackage file.

vpuid

A vector of VPU IDs to filter the layers. If `NULL`, no filtering is applied. Default is `NULL`.

outfile

A string specifying the path to write the filtered layers to a new GeoPackage. If `NULL`, the layers are returned as a list. Default is `NULL`.

Value

If `outfile` is `NULL`, returns a list where each element is a filtered spatial layer (`sf` object). If `outfile` is provided, returns the path to the output GeoPackage.

Details

The function reads all layers from the provided GeoPackage, excluding the "error" layer. For each layer, the data is optionally filtered by the provided `vpuid` and then processed into `sf` objects. If an output file path is provided, the filtered layers are written to a new GeoPackage. Otherwise, the layers are stored in a list and returned.

Examples

if (FALSE) { # \dontrun{
# Example 1: Retrieve filtered layers as a list
fabric <- get_vpu_fabric("path/to/geopackage.gpkg", vpuid = c("01", "02"))

# Example 2: Write filtered layers to a new GeoPackage
get_vpu_fabric("path/to/geopackage.gpkg", vpuid = c("01", "02"), outfile = "output.gpkg")
} # }