From 2d274d84a7a66cf1b4ac989b99254370e9808b4f Mon Sep 17 00:00:00 2001 From: Dorchies David <david.dorchies@inrae.fr> Date: Thu, 5 Aug 2021 16:10:38 +0200 Subject: [PATCH] feat: add `get_hydrometrie_stations` Refs #7 --- NAMESPACE | 1 + R/get_hydrometrie_stations.R | 29 +++++++++++++++++++++++++++++ R/hubeau.R | 9 +++++++++ inst/config.yml | 24 ++++++++++++++++++++++++ man/get_hydrometrie_stations.Rd | 31 +++++++++++++++++++++++++++++++ man/hubeau.Rd | 10 ++++++++++ 6 files changed, 104 insertions(+) create mode 100644 R/get_hydrometrie_stations.R create mode 100644 man/get_hydrometrie_stations.Rd diff --git a/NAMESPACE b/NAMESPACE index a4a1b40..0bf79c9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(doApiQuery) export(get_available_params) +export(get_hydrometrie_stations) export(get_indicateurs_services_communes) export(get_indicateurs_services_indicateurs) export(get_prelevements_chroniques) diff --git a/R/get_hydrometrie_stations.R b/R/get_hydrometrie_stations.R new file mode 100644 index 0000000..8e7899e --- /dev/null +++ b/R/get_hydrometrie_stations.R @@ -0,0 +1,29 @@ +#' Retrieve hydrometric stations from API "Hydrométrie" +#' +#' See the API documentation for available filter parameters: \url{https://hubeau.eaufrance.fr/page/api-hydrometrie} +#' +#' @template param_get_common +#' @param code_sandre_reseau_station optional [logical] indicating if `code_sandre_reseau_station` field is included in the result; if so, one line is added by item and other fields are repeated +#' +#' @return a [tibble::tibble] with all available parameters in columns and one row by device, year and usage. +#' @export +#' +#' @examples +#' # For retrieving the hydrometric stations in the department of Aube +#' get_hydrometrie_stations(list(code_departement = "10")) +#' +get_hydrometrie_stations <- function(params, code_sandre_reseau_station = FALSE, cfg = config::get(file = system.file("config.yml", + package = "hubeau"))) { + l <- doApiQuery(api = "hydrometrie", + operation = "stations", + params = params, + cfg = cfg) + l <- lapply(l, function(x) { + if (!code_sandre_reseau_station) { + x$code_sandre_reseau_station <- NULL + } + x$geometry <- NULL + x + }) + convert_list_to_tibble(l) +} diff --git a/R/hubeau.R b/R/hubeau.R index 3ba2d41..d994ce5 100644 --- a/R/hubeau.R +++ b/R/hubeau.R @@ -4,6 +4,14 @@ #' #' Currently available APIs and related "operations" are listed below. #' +#' **API "Hydrométrie"** +#' +#' API documentation: \url{https://hubeau.eaufrance.fr/page/api-hydrometrie} +#' +#' Available functions: +#' +#' - [get_hydrometrie_stations] +#' #' **API "Indicateurs des services"** #' #' API documentation: \url{https://hubeau.eaufrance.fr/page/api-indicateurs-services} @@ -20,6 +28,7 @@ #' Available functions: #' #' - [get_prelevements_chroniques] +#' - [get_prelevements_ouvrages] #' - [get_prelevements_points_prelevement] #' #' @docType package diff --git a/inst/config.yml b/inst/config.yml index 47c8e6a..542126d 100644 --- a/inst/config.yml +++ b/inst/config.yml @@ -95,3 +95,27 @@ default: - code_departement - fields - type_service + hydrometrie: + path: v1/hydrometrie + operations: + stations: + path: referentiel/stations + fields: + - bbox + - code_commune_station + - code_cours_eau + - code_departement + - code_region + - code_sandre_reseau_station + - code_site + - code_station + - date_fermeture_station + - date_ouverture_station + - distance + - en_service + - fields + - latitude + - libelle_cours_eau + - libelle_site + - libelle_station + - longitude diff --git a/man/get_hydrometrie_stations.Rd b/man/get_hydrometrie_stations.Rd new file mode 100644 index 0000000..8f8b1c1 --- /dev/null +++ b/man/get_hydrometrie_stations.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_hydrometrie_stations.R +\name{get_hydrometrie_stations} +\alias{get_hydrometrie_stations} +\title{Retrieve hydrometric stations from API "Hydrométrie"} +\usage{ +get_hydrometrie_stations( + params, + code_sandre_reseau_station = FALSE, + 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{code_sandre_reseau_station}{optional \link{logical} indicating if \code{code_sandre_reseau_station} field is included in the result; if so, one line is added by item and other fields are repeated} + +\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 device, year and usage. +} +\description{ +See the API documentation for available filter parameters: \url{https://hubeau.eaufrance.fr/page/api-hydrometrie} +} +\examples{ +# For retrieving the hydrometric stations in the department of Aube +get_hydrometrie_stations(list(code_departement = "10")) + +} diff --git a/man/hubeau.Rd b/man/hubeau.Rd index 3de365c..130be14 100644 --- a/man/hubeau.Rd +++ b/man/hubeau.Rd @@ -10,6 +10,15 @@ The 'hubeau' package provides functions for APIs and related "operations". These \details{ Currently available APIs and related "operations" are listed below. +\strong{API "Hydrométrie"} + +API documentation: \url{https://hubeau.eaufrance.fr/page/api-hydrometrie} + +Available functions: +\itemize{ +\item \link{get_hydrometrie_stations} +} + \strong{API "Indicateurs des services"} API documentation: \url{https://hubeau.eaufrance.fr/page/api-indicateurs-services} @@ -27,6 +36,7 @@ API documentation: \url{https://hubeau.eaufrance.fr/page/api-prelevements-eau} Available functions: \itemize{ \item \link{get_prelevements_chroniques} +\item \link{get_prelevements_ouvrages} \item \link{get_prelevements_points_prelevement} } } -- GitLab