Skip to content

Commit

Permalink
Merge branch 'main' into sf-related-pkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle authored Feb 28, 2024
2 parents 8dc3969 + 3ef9dbe commit 4480102
Show file tree
Hide file tree
Showing 31 changed files with 386 additions and 177 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
^Meta$
^attic$
^codemeta\.json$
^vignettes/EMODnetWFS\.Rmd\.orig$
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Version: 2.0.1.9001
Authors@R: c(
person("Anna", "Krystalli", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-2378-4915")),
person("Salvador", "Fernández-Bejarano", , "[email protected]", role = c("ctb", "cre"),
person("Salvador", "Fernández-Bejarano", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0535-7677")),
person("Thomas J", "Webb", , "[email protected]", role = "ctb"),
person("European Marine Observation Data Network (EMODnet) Biology project", "European Commission's Directorate - General for Maritime Affairs and Fisheries (DG MARE)", , "[email protected]", role = "cph"),
Expand All @@ -15,7 +15,8 @@ Authors@R: c(
Description: Access and interrogate EMODnet Web Feature Service data
through R.
License: MIT + file LICENSE
URL: https://emodnet.github.io/EMODnetWFS/, https://github.com/EMODnet/EMODnetWFS
URL: https://emodnet.github.io/EMODnetWFS/,
https://github.com/EMODnet/EMODnetWFS
BugReports: https://github.com/EMODnet/EMODnetWFS/issues
Depends:
R (>= 3.6.0)
Expand All @@ -28,7 +29,7 @@ Imports:
lifecycle,
magrittr,
memoise,
ows4R (>= 0.3),
ows4R (>= 0.3-4),
purrr,
rlang,
sf,
Expand All @@ -48,14 +49,15 @@ Suggests:
testthis,
webmockr,
withr
VignetteBuilder:
knitr
Remotes:
eblondel/ows4R,
nealrichardson/httptest,
r-spatial/mapview
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
SystemRequirements: C++11, GDAL (>= 2.0.1), GEOS (>= 3.4.0), PROJ (>=
Expand Down
24 changes: 19 additions & 5 deletions R/EMODnetWFS-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,33 @@ emodnetwfs_user_agent <- function() {
version <- as.character(utils::packageVersion("EMODnetWFS"))

if (nzchar(Sys.getenv("EMODNETWFS_CI"))) {
return(sprintf("EMODnetWFS R package %s CI https://github.com/EMODnet/EMODnetWFS", version))
return(
sprintf(
"EMODnetWFS R package %s CI https://github.com/EMODnet/EMODnetWFS",
version
)
)
}

gh_username <- try(whoami::gh_username(), silent = TRUE)
if (!inherits(gh_username, "try-error") && gh_username %in% emodnetwfs_collaborators()) {
return(sprintf("EMODnetWFS R package %s DEV https://github.com/EMODnet/EMODnetWFS", version))
if (!inherits(gh_username, "try-error") &&
gh_username %in% emodnetwfs_collaborators()) {
return(
sprintf(
"EMODnetWFS R package %s DEV https://github.com/EMODnet/EMODnetWFS",
version
)
)
}

sprintf("EMODnetWFS R package %s https://github.com/EMODnet/EMODnetWFS", version)
sprintf(
"EMODnetWFS R package %s https://github.com/EMODnet/EMODnetWFS",
version
)
}

globalVariables(c("layer_name", "n"))

release_bullets <- function() {
c('update vignette with knitr::knit("vignettes/EMODnetWFS.Rmd.orig", output = "vignettes/EMODnetWFS.Rmd")')
c('update vignette with knitr::knit("vignettes/EMODnetWFS.Rmd.orig", output = "vignettes/EMODnetWFS.Rmd")')
}
32 changes: 23 additions & 9 deletions R/client.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
#'
#' @param service the EMODnet OGC WFS service name.
#' For available services, see [`emodnet_wfs()`].
#' @param service_version `r lifecycle::badge('deprecated')` the WFS service version. Now always "2.0.0".
#' @param logger the logger. Either `NULL` (no logging info), `"INFO"` (log about ows4R requests)
#' @param service_version `r lifecycle::badge('deprecated')`
#' the WFS service version. Now always "2.0.0".
#' @param logger the logger. Either `NULL` (no logging info), `"INFO"`
#' (log about ows4R requests)
#' or `"DEBUG"` (including curl details).
#'
#' @return An [`ows4R::WFSClient`] R6 object with methods for interfacing an OGC Web Feature Service.
#' @return An [`ows4R::WFSClient`] R6 object with methods for interfacing an
#' OGC Web Feature Service.
#' @export
#'
#' @seealso `WFSClient` in package `ows4R`.
#' @examples
#' \dontrun{
#' wfs <- emodnet_init_wfs_client(service = "bathymetry")
#' }
emodnet_init_wfs_client <- function(service, service_version = NULL, logger = NULL) {
deprecate_message_service_version(service_version, "deprecate_message_service_version")
emodnet_init_wfs_client <- function(service,
service_version = NULL,
logger = NULL) {
deprecate_message_service_version(
service_version,
"deprecate_message_service_version"
)

check_service_name(service)

Expand Down Expand Up @@ -97,12 +105,18 @@ check_service <- function(request) {
if (httr::http_error(request)) {
cli_alert_danger("HTTP Status: {httr::http_status(request)$message}")

is_monitor_up <- !is.null(curl::nslookup("monitor.emodnet.eu", error = FALSE))
is_monitor_up <- !is.null(
curl::nslookup("monitor.emodnet.eu", error = FALSE)
)
if (interactive() && is_monitor_up) {
browse_monitor <- utils::askYesNo("Browse the EMODnet OGC monitor?", FALSE, prompts = "yes/no/cancel")
browse_monitor <- utils::askYesNo(
"Browse the EMODnet OGC monitor?",
FALSE,
prompts = "yes/no/cancel"
)
if (is.na(browse_monitor)) browse_monitor <- FALSE
if (browse_monitor) {
utils::browseURL("https://monitor.emodnet.eu/resources?lang=en&resource_type=OGC:WFS")
utils::browseURL("https://monitor.emodnet.eu/resources?lang=en&resource_type=OGC:WFS") # nolint
}
}

Expand All @@ -115,7 +129,7 @@ check_service <- function(request) {
cli::cli_abort(
c(
"An exception has occurred.",
i = "Please raise an issue in {packageDescription('EMODnetWFS')$BugReports}"
i = "Please raise an issue in {packageDescription('EMODnetWFS')$BugReports}" # nolint
)
)
}
Expand Down
22 changes: 16 additions & 6 deletions R/info.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@
#' @importFrom memoise memoise
#' @details To minimize the number of requests sent to webservices,
#' these functions use `memoise` to cache results inside the active R session.
#' To clear the cache, re-start R or run `memoise::forget(emodnet_get_wfs_info)`/`memoise::forget(emodnet_get_layer_info)`.
#' To clear the cache, re-start R or
#' run `memoise::forget(emodnet_get_wfs_info)`/
#' `memoise::forget(emodnet_get_layer_info)`.
#' @export
emodnet_get_layer_info <- memoise::memoise(.emodnet_get_layer_info)

.emodnet_get_wfs_info <- function(wfs = NULL, service = NULL, service_version = NULL) {
.emodnet_get_wfs_info <- function(wfs = NULL,
service = NULL,
service_version = NULL) {
deprecate_message_service_version(service_version, "emodnet_get_wfs_info")

if (is.null(wfs) && is.null(service)) {
Expand All @@ -59,7 +63,10 @@ emodnet_get_layer_info <- memoise::memoise(.emodnet_get_layer_info)
service_url = capabilities$getUrl(),
layer_name = purrr::map_chr(capabilities$getFeatureTypes(), ~ .x$getName()),
title = purrr::map_chr(capabilities$getFeatureTypes(), ~ .x$getTitle()),
abstract = purrr::map_chr(capabilities$getFeatureTypes(), ~ get_abstract_null(.x)),
abstract = purrr::map_chr(
capabilities$getFeatureTypes(),
~ get_abstract_null(.x)
),
class = purrr::map_chr(capabilities$getFeatureTypes(), ~ .x$getClassName()),
format = purrr::map_chr(capabilities$getFeatureTypes(), guess_layer_format)
) %>%
Expand All @@ -71,11 +78,14 @@ emodnet_get_layer_info <- memoise::memoise(.emodnet_get_layer_info)
}
#' Get WFS available layer information
#'
#' @param wfs A `WFSClient` R6 object with methods for interfacing an OGC Web Feature Service.
#' @param wfs A `WFSClient` R6 object with methods for interfacing an
#' OGC Web Feature Service.
#' @inheritParams emodnet_init_wfs_client
#' @return a tibble containing metadata on each layer available from the service.
#' @return a tibble containing metadata on each layer available from the
#' service.
#' @export
#' @describeIn emodnet_get_wfs_info Get info on all layers from am EMODnet WFS service.
#' @describeIn emodnet_get_wfs_info Get info on all layers from
#' an EMODnet WFS service.
#' @examples
#' \dontrun{
#' emodnet_get_wfs_info(service = "bathymetry")
Expand Down
64 changes: 49 additions & 15 deletions R/layer_attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@
#' @param layer character sting of layer name. To get info on layers, including
#' `layer_name` use [emodnet_get_wfs_info()].
#'
#' @return output of `summary()` on the attributes (variables) in a given layer for a given service.
#' @return output of `summary()` on the attributes (variables) in a given layer
#' for a given service.
#' @export
#'
#' @examples
#' \dontrun{
#' layer_attributes_summarise(service = "human_activities", layer = "maritimebnds")
#' layer_attributes_summarise(
#' service = "human_activities",
#' layer = "maritimebnds"
#' )
#' }
layer_attributes_summarise <- function(wfs = NULL,
service = NULL,
service_version = NULL,
layer) {
deprecate_message_service_version(service_version, "layer_attributes_summarise")
deprecate_message_service_version(
service_version,
"layer_attributes_summarise"
)
summary(
layer_attributes_tbl(
wfs = wfs,
Expand All @@ -37,12 +44,18 @@ layer_attributes_summarise <- function(wfs = NULL,
#'
#' @examples
#' \dontrun{
#' layer_attribute_descriptions(service = "human_activities", layer = "maritimebnds")
#' layer_attribute_descriptions(
#' service = "human_activities",
#' layer = "maritimebnds"
#' )
#' }
layer_attribute_descriptions <- function(wfs = NULL,
service = NULL,
service_version = NULL, layer) {
deprecate_message_service_version(service_version, "layer_attribute_descriptions")
deprecate_message_service_version(
service_version,
"layer_attribute_descriptions"
)

wfs <- wfs %||% emodnet_init_wfs_client(service)
check_wfs(wfs)
Expand All @@ -62,13 +75,19 @@ layer_attribute_descriptions <- function(wfs = NULL,
#'
#' @examples
#' \dontrun{
#' layer_attributes_get_names(service = "human_activities", layer = "maritimebnds")
#' layer_attributes_get_names(
#' service = "human_activities",
#' layer = "maritimebnds"
#' )
#' }
layer_attributes_get_names <- function(wfs = NULL,
service = NULL,
service_version = NULL,
layer) {
deprecate_message_service_version(service_version, "layer_attributes_get_names")
deprecate_message_service_version(
service_version,
"layer_attributes_get_names"
)

layer_attribute_descriptions(
wfs = wfs,
Expand All @@ -85,7 +104,8 @@ layer_attributes_get_names <- function(wfs = NULL,
#' @inheritParams emodnet_init_wfs_client
#' @inheritParams emodnet_get_wfs_info
#'
#' @return Detailed summary of individual attribute (variable). Particularly useful for inspecting
#' @return Detailed summary of individual attribute (variable). Particularly
#' useful for inspecting
#' factor or character variable levels or unique values.
#' @export
#'
Expand Down Expand Up @@ -116,7 +136,10 @@ layer_attribute_inspect <- function(wfs = NULL,
choices = layer_attributes_get_names(wfs, layer = layer)
)

attribute_vector <- wfs$getFeatures(namespaced_layer, PROPERTYNAME = attribute)[[attribute]]
attribute_vector <- wfs$getFeatures(
namespaced_layer,
PROPERTYNAME = attribute
)[[attribute]]

if (inherits(attribute_vector, "sfc")) {
attribute_type <- "geometry"
Expand All @@ -141,9 +164,12 @@ layer_attribute_inspect <- function(wfs = NULL,
#' @inheritParams emodnet_get_wfs_info
#' @inheritParams layer_attributes_summarise
#'
#' @return tibble of layer attribute (variable) values with geometry column removed.
#' @details Request excluding spatial information can be significantly faster. Can be
#' useful for inspecting attribute values and constructing feature filters for more
#' @return tibble of layer attribute (variable) values
#' with geometry column removed.
#' @details Request excluding spatial information can be significantly faster.
#' Can be
#' useful for inspecting attribute values and constructing feature filters
#' for more
#' targeted and faster layer download.
#' @export
#'
Expand All @@ -168,7 +194,10 @@ layer_attributes_tbl <- function(wfs = NULL,
attributes <- layer_attributes_get_names(wfs, layer = layer)
attributes <- attributes[attributes != get_layer_geom_name(layer, wfs)]

wfs$getFeatures(namespaced_layer, PROPERTYNAME = paste(attributes, collapse = ",")) %>%
wfs$getFeatures(
namespaced_layer,
PROPERTYNAME = paste(attributes, collapse = ",")
) %>%
sf::st_drop_geometry() %>%
tibble::as_tibble()
}
Expand Down Expand Up @@ -196,7 +225,9 @@ get_layer_geom_name <- function(layer, wfs) {
desc$name[desc$type == "geometry"]
}

get_layer_default_crs <- function(layer, wfs, output = c("crs", "epsg.text", "epsg.num")) {
get_layer_default_crs <- function(layer,
wfs,
output = c("crs", "epsg.text", "epsg.num")) {
check_wfs(wfs)
output <- match.arg(output, several.ok = FALSE)

Expand All @@ -211,7 +242,10 @@ get_layer_default_crs <- function(layer, wfs, output = c("crs", "epsg.text", "ep
return(crs)
}

epsg.text <- regmatches(crs$input, regexpr("epsg\\:[[:digit:]]{4}", crs$input))
epsg.text <- regmatches(
crs$input,
regexpr("epsg\\:[[:digit:]]{4}", crs$input)
)
if (output == "epsg.text") {
return(epsg.text)
}
Expand Down
Loading

0 comments on commit 4480102

Please sign in to comment.