Skip to contents

This function downloads a single vector layer from a WFS (Web Feature Service) endpoint and saves it locally in GeoJSON or another supported format.

Usage

ngr_spk_geoserv_dlv(
  url_geoserver = "https://maps.skeenasalmon.info/geoserver/ows",
  dir_out = NULL,
  layer_name_raw = NULL,
  layer_name_out = stringr::str_extract(layer_name_raw, "(?<=:).*"),
  crs = 3005,
  bbox = NULL,
  format_out = "json",
  discard_no_features = TRUE
)

Arguments

url_geoserver

character A single URL string to the GeoServer WFS endpoint.

dir_out

character A directory path where the output file will be saved. Must exist or be creatable.

layer_name_raw

character A WFS layer name, usually including a namespace (e.g., geonode:LayerName).

layer_name_out

character Optional. Output file name without extension. Defaults to the name extracted from layer_name_raw.

crs

integer EPSG code for the coordinate reference system to request from the server. Default is 3005.

bbox

bbox or numeric Optional. A bounding box to filter features spatially. Must be in the same CRS or coercible.

format_out

character WFS output format. Common values: "json", "GML2", "shape-zip". Default is "json" and function will need to be modified in the future to accommodate other formats.

discard_no_features

logical Optional. If TRUE, automatically deletes downloaded files that have zero features. Default is TRUE.

Value

Invisibly returns the output file path on success. Prints status messages to console.

Details

By default, the layer_name_out is inferred from layer_name_raw by removing a namespace prefix (e.g., geonode:), which is common in GeoServer layers.

If a bounding box is passed as a sf::st_bbox() object and it has a different CRS than the target CRS, it will be transformed using sf::st_transform().

Regardless of discard_no_features, the function will scan the first few lines of the downloaded GeoJSON file and warn if no features are found. If discard_no_features = TRUE, the empty file is deleted.

Examples

if (FALSE) { # \dontrun{
dir_out <- "data/gis/skt/esi_sows"
layer_name_raw <- "geonode:UBulkley_wshed"
ngr_spk_geoserv_dl(
  dir_out = dir_out,
  layer_name_raw = layer_name_raw
)
} # }