Skip to content

Commit

Permalink
feat: handle iho spatial layer - fix #30
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Feb 8, 2024
1 parent 2fca9f5 commit 7d122cf
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Imports:
jsonlite,
lubridate,
rlang,
sf,
tidyr,
utils,
vroom
Expand Down
8 changes: 8 additions & 0 deletions R/filenames.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ cpr_south_filename <- function() "FORCIS_cpr_south_"
#' @noRd

sediment_trap_filename <- function() "FORCIS_trap_"



#' Sediment Traps file name
#'
#' @noRd

iho_oceans_filename <- function() "iho_oceans_boundaries"
66 changes: 66 additions & 0 deletions R/gets.R
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,72 @@ get_sediment_trap_data <- function(path = ".", version = NULL,



#' Download and read IHO spatial layer
#'
#' Used in the `spatial_filter_*()` functions
#'
#' @noRd

get_iho_data <- function(path = ".", version = NULL,
check_for_update = TRUE, overwrite = FALSE,
timeout = 60) {

## Check args ----

is_character(path)
check_zen_version(version)


## Check/set version ----

version <- set_zen_version(version, ask = check_for_update)


## Build outputs directory ----

path <- file.path(path, "forcis-db", paste0("version-", version))

if (!dir.exists(path)) {
dir.create(path, recursive = TRUE)
}


## Download file (if required) ----

file_name <- list.files(path, pattern = iho_oceans_filename())

if (!length(file_name)) {

forcis_meta <- zen_get_version_info(version = version)
forcis_files <- forcis_meta$"files"

pos <- grep(iho_oceans_filename(), forcis_files$"key")

if (length(pos) == 1) {

download_file(url = forcis_files[pos, "links"]$"self",
path = path,
file = forcis_files[pos, "key"],
overwrite = overwrite,
timeout = timeout)

} else {

stop("Unable to download the 'IHO' dataset", call. = FALSE)
}
}


## Read data ----

file_name <- list.files(path, pattern = iho_oceans_filename())

data <- readRDS(file.path(path, file_name))
sf::st_as_sf(data)
}



#' Download a csv file
#'
#' @param file a `character` of length 1. The name of the csv to download.
Expand Down

0 comments on commit 7d122cf

Please sign in to comment.