diff --git a/R/filter_by_ocean.R b/R/filter_by_ocean.R index 8382791..b6c2448 100644 --- a/R/filter_by_ocean.R +++ b/R/filter_by_ocean.R @@ -34,22 +34,12 @@ filter_by_ocean <- function(data, ocean) { data_sf <- data_to_sf(data) - - - ## Read IHO layer ---- - - iho <- read_iho_data(check_for_update = FALSE) - iho <- iho[iho$"NAME" %in% ocean, ] - - - ## Project spatial objects into Robinson system ---- - - iho <- sf::st_transform(iho, sf::st_crs(crs_robinson())) - + ## Spatial filter ---- - inter <- suppressWarnings(sf::st_intersects(data_sf, iho, sparse = FALSE)) + inter <- suppressWarnings(sf::st_intersects(data_sf, iho_boundaries, + sparse = FALSE)) data[which(apply(inter, 1, any)), ] } diff --git a/R/get_ocean_names.R b/R/get_ocean_names.R index 5907767..61695bd 100644 --- a/R/get_ocean_names.R +++ b/R/get_ocean_names.R @@ -20,5 +20,5 @@ get_ocean_names <- function() { - read_iho_data(check_for_update = FALSE)$"NAME" + iho_boundaries$"NAME" } diff --git a/R/internals.R b/R/internals.R index 9388a62..ba585ed 100644 --- a/R/internals.R +++ b/R/internals.R @@ -1,72 +1,3 @@ -#' Download and read IHO spatial layer -#' -#' @noRd - -read_iho_data <- function(path = ".", - version = options()$"forcis_version", - check_for_update = options()$"check_for_update", - overwrite = FALSE, timeout = 60) { - - ## Check args ---- - - check_if_character(path) - check_version(version) - - - ## Check/set version ---- - - if (is.null(check_for_update)) { - check_for_update <- TRUE - } - - version <- set_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 <- 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 #' #' @noRd @@ -159,14 +90,6 @@ sediment_trap_filename <- function() "FORCIS_trap_" -#' Sediment Traps file name -#' -#' @noRd - -iho_oceans_filename <- function() "iho_oceans_boundaries" - - - #' Vector of device types available in FORCIS database #' #' @noRd diff --git a/R/sysdata.rda b/R/sysdata.rda index ae93bda..59bfca7 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/tests/testthat/test-variables.R b/tests/testthat/test-variables.R index 5c71fdc..7e8e35e 100644 --- a/tests/testthat/test-variables.R +++ b/tests/testthat/test-variables.R @@ -82,19 +82,6 @@ test_that("Test sediment_trap_filename() for success", { -## iho_oceans_filename() ---- - -test_that("Test iho_oceans_filename() for success", { - - x <- iho_oceans_filename() - - expect_equal(x, "iho_oceans_boundaries") - expect_equal(class(x), "character") - expect_equal(length(x), 1L) -}) - - - ## get_required_columns() ---- test_that("Test get_required_columns() for success", {