diff --git a/NAMESPACE b/NAMESPACE index f3d41cac6b6a17f5eff5b24510d46ba97f92162c..09c1aa36b06a4658da1320686e7d3660c9000168 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(doApiQuery) export(get_available_params) +export(get_hydrometrie_observations_tr) export(get_hydrometrie_sites) export(get_hydrometrie_stations) export(get_indicateurs_services_communes) diff --git a/R/get_hydrometrie_observations_tr.R b/R/get_hydrometrie_observations_tr.R new file mode 100644 index 0000000000000000000000000000000000000000..7c48dc36769695a7d0094b6087998e21ef88f510 --- /dev/null +++ b/R/get_hydrometrie_observations_tr.R @@ -0,0 +1,35 @@ +#' Retrieve hydrometric "real time" observations from API "Hydrométrie" +#' +#' See the API documentation for available filter parameters: \url{https://hubeau.eaufrance.fr/page/api-hydrometrie} +#' +#' @template param_get_common +#' +#' @return a [tibble::tibble] with all available parameters in columns and one row by time step and by station. +#' @export +#' +#' @examples +#' # For retrieving the hydrometric last real time observed discharge at station 'H020302002' +#' get_hydrometrie_observations_tr(list(code_entite = "H0203020", grandeur_hydro = "Q")) +#' +get_hydrometrie_observations_tr <- function(params, + unique_site = TRUE, + cfg = config::get(file = system.file("config.yml", + package = "hubeau"))) { + l <- doApiQuery( + api = "hydrometrie", + operation = "observations_tr", + params = params, + cfg = cfg + ) + l <- lapply(l, function(x) { + x$geometry <- NULL + if (is.null(x$code_station)) { + # See bug https://github.com/BRGM/hubeau/issues/73 + NULL + } else { + x + } + }) + l[sapply(l, is.null)] <- NULL + convert_list_to_tibble(l) +} diff --git a/R/hubeau.R b/R/hubeau.R index 02c8aff6d77231ce5bf85f5cc72f303e7d860694..afb1eec73e6a2005e6d13662c40e86ab96d77ea6 100644 --- a/R/hubeau.R +++ b/R/hubeau.R @@ -10,6 +10,7 @@ #' #' Available functions: #' +#' - [get_hydrometrie_observations_tr] #' - [get_hydrometrie_sites] #' - [get_hydrometrie_stations] #' diff --git a/inst/config.yml b/inst/config.yml index 74f4d628ff8d8f50053806601c1032d77fc58251..55ff964c15bc7f17c179c807628f1b8818429da8 100644 --- a/inst/config.yml +++ b/inst/config.yml @@ -136,3 +136,17 @@ default: - libelle_cours_eau - libelle_site - longitude + observations_tr: + path: observations_tr + fields: + - bbox + - code_entite + - cursor + - date_debut_obs + - date_fin_obs + - distance + - fields + - grandeur_hydro + - latitude + - longitude + - timestep diff --git a/man/get_hydrometrie_observations_tr.Rd b/man/get_hydrometrie_observations_tr.Rd new file mode 100644 index 0000000000000000000000000000000000000000..a5149171ad916963d09aa3d5206f51c14c97e14f --- /dev/null +++ b/man/get_hydrometrie_observations_tr.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_hydrometrie_observations_tr.R +\name{get_hydrometrie_observations_tr} +\alias{get_hydrometrie_observations_tr} +\title{Retrieve hydrometric "real time" observations from API "Hydrométrie"} +\usage{ +get_hydrometrie_observations_tr( + params, + unique_site = TRUE, + cfg = config::get(file = system.file("config.yml", package = "hubeau")) +) +} +\arguments{ +\item{params}{a \link{list} the list of parameters of the queries and their values in the format \code{list(ParamName = "Param value", ...)}, use the function \link{get_available_params} for a list of the available parameters for a given operation in an API and see the API documentation for the complete list of available filter parameters} + +\item{cfg}{a \link{config} object Configuration of the communication. Use by default the internal package +configuration} +} +\value{ +a \link[tibble:tibble]{tibble::tibble} with all available parameters in columns and one row by time step and by station. +} +\description{ +See the API documentation for available filter parameters: \url{https://hubeau.eaufrance.fr/page/api-hydrometrie} +} +\examples{ +# For retrieving the hydrometric last real time observed discharge at station 'H020302002' +get_hydrometrie_observations_tr(list(code_entite = "H0203020", grandeur_hydro = "Q")) + +} diff --git a/man/hubeau.Rd b/man/hubeau.Rd index f43f154a7827e0df84a17bc7c19021cd4879a951..312ba33204d82104da32043aa9899f3d5357f4a7 100644 --- a/man/hubeau.Rd +++ b/man/hubeau.Rd @@ -16,6 +16,7 @@ API documentation: \url{https://hubeau.eaufrance.fr/page/api-hydrometrie} Available functions: \itemize{ +\item \link{get_hydrometrie_observations_tr} \item \link{get_hydrometrie_sites} \item \link{get_hydrometrie_stations} }