|
|
|
@ -1,11 +1,68 @@
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
#
|
|
|
|
|
#' Get the Measurements of a Phenomenon on opensensemap.org
|
|
|
|
|
#'
|
|
|
|
|
#' Measurements can be retrieved either for a set of boxes, or through a spatial
|
|
|
|
|
#' bounding box filter. To get all measurements, the \code{default} function applies
|
|
|
|
|
#' a bounding box spanning the whole world.
|
|
|
|
|
#'
|
|
|
|
|
#' @param phenomenon The phenomenon to retrieve measurements for
|
|
|
|
|
#' @param exposure Filter sensors by their exposure ('indoor', 'outdoor', 'mobile')
|
|
|
|
|
#' @param from A \code{POSIXt} like object to select a time interval
|
|
|
|
|
#' @param to A \code{POSIXt} like object to select a time interval
|
|
|
|
|
#' @param columns Select specific column in the output (see oSeM documentation)
|
|
|
|
|
#' @param endpoint The URL of the openSenseMap API
|
|
|
|
|
#'
|
|
|
|
|
#' @return An \code{osem_measurements} \code{data.frame} containing the
|
|
|
|
|
#' requested measurements
|
|
|
|
|
#'
|
|
|
|
|
#' @export
|
|
|
|
|
#' @family osem_measurements
|
|
|
|
|
#' @seealso \href{https://docs.opensensemap.org/#api-Measurements-getDataMulti}{openSenseMap API documentation}
|
|
|
|
|
osem_measurements = function (x, ...) UseMethod('osem_measurements')
|
|
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
#
|
|
|
|
|
#' Get the Measurements of a Phenomenon from all sensors
|
|
|
|
|
#'
|
|
|
|
|
#' @param ... Passed on to \code{\link{osem_measurements.bbox}}
|
|
|
|
|
#' @inherit osem_measurements seealso return
|
|
|
|
|
#' @inheritParams osem_measurements
|
|
|
|
|
#'
|
|
|
|
|
#' @export
|
|
|
|
|
#' @family osem_measurements
|
|
|
|
|
#' @seealso \code{\link{osem_measurements.bbox}}
|
|
|
|
|
#' @seealso \href{https://docs.opensensemap.org/#api-Measurements-getDataMulti}{openSenseMap API documentation}
|
|
|
|
|
#'
|
|
|
|
|
#' @examples
|
|
|
|
|
#' osem_measurements('PM2.5')
|
|
|
|
|
osem_measurements.default = function (phenomenon, ...) {
|
|
|
|
|
bbox = structure(c(-180, -90, 180, 90), class = 'bbox')
|
|
|
|
|
osem_measurements(bbox, phenomenon, ...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# /boxes/data?bbox=
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
#
|
|
|
|
|
#' Get the Measurements of a Phenomenon by a spatial filter
|
|
|
|
|
#'
|
|
|
|
|
#' @param bbox A \code{\link[sf]{st_bbox}} to select sensors spatially
|
|
|
|
|
#' @inheritParams phenomenon,exposure,from,to,columns,endpoint osem_measurements
|
|
|
|
|
#'
|
|
|
|
|
#' @return An \code{osem_measurements} \code{data.frame} containing the
|
|
|
|
|
#' requested measurements
|
|
|
|
|
#'
|
|
|
|
|
#' @export
|
|
|
|
|
#' @family osem_measurements
|
|
|
|
|
#' @seealso \href{https://docs.opensensemap.org/#api-Measurements-getDataMulti}{openSenseMap API documentation}
|
|
|
|
|
#' @seealso \code{\link[sf]{st_bbox}}
|
|
|
|
|
#'
|
|
|
|
|
#' @examples
|
|
|
|
|
#' bbox = structure(c(7.5, 51, 8, 52), class = 'bbox')
|
|
|
|
|
#' osem_measurements(bbox, 'Temperature')
|
|
|
|
|
#'
|
|
|
|
|
#'
|
|
|
|
|
#' bbox2 = sf::st_point(c(7, 51)) %>% sf::st_bbox()
|
|
|
|
|
#' osem_measurements(bbox2, 'Temperature', exposure = 'outdoor')
|
|
|
|
|
osem_measurements.bbox = function (bbox, phenomenon, exposure = NA,
|
|
|
|
|
from = NA, to = NA,
|
|
|
|
|
columns = NA,
|
|
|
|
@ -14,7 +71,27 @@ osem_measurements.bbox = function (bbox, phenomenon, exposure = NA,
|
|
|
|
|
do.call(get_measurements_, query)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# /boxes/data?boxId=1,2,3,4
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
#
|
|
|
|
|
#' Get the Measurements of a Phenomenon for a set of senseBoxes
|
|
|
|
|
#'
|
|
|
|
|
#' @param boxes A \code{sensebox} \code{data.frame} to select boxes from which
|
|
|
|
|
#' measurements will be retrieved
|
|
|
|
|
#' @inheritParams phenomenon,exposure,from,to,columns,endpoint osem_measurements
|
|
|
|
|
#'
|
|
|
|
|
#' @return An \code{osem_measurements} \code{data.frame} containing the
|
|
|
|
|
#' requested measurements
|
|
|
|
|
#'
|
|
|
|
|
#' @export
|
|
|
|
|
#' @family osem_measurements
|
|
|
|
|
#' @seealso [osem_boxes()]
|
|
|
|
|
#' @seealso [osem_box()]
|
|
|
|
|
#'
|
|
|
|
|
#' @examples
|
|
|
|
|
#' osem_boxes(grouptag = 'ifgi') %>% get_measurements(phenomenon = 'Temperatur')
|
|
|
|
|
#'
|
|
|
|
|
#' b = osem_box('593bcd656ccf3b0011791f5a')
|
|
|
|
|
#' get_measurements(b, phenomenon = 'Temperatur')
|
|
|
|
|
osem_measurements.sensebox = function (boxes, phenomenon, exposure = NA,
|
|
|
|
|
from = NA, to = NA,
|
|
|
|
|
columns = NA,
|
|
|
|
@ -23,6 +100,16 @@ osem_measurements.sensebox = function (boxes, phenomenon, exposure = NA,
|
|
|
|
|
do.call(get_measurements_, query)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
#
|
|
|
|
|
#' Validates and parses the Parameters for \code{osem_measurements()}
|
|
|
|
|
#'
|
|
|
|
|
#' @param params A named \code{list} of parameters
|
|
|
|
|
#'
|
|
|
|
|
#' @return A named \code{list} of parsed parameters.
|
|
|
|
|
#'
|
|
|
|
|
#' @family osem_internal
|
|
|
|
|
#' @noRd
|
|
|
|
|
parse_get_measurements_params = function (params) {
|
|
|
|
|
if (is.null(params$phenomenon) | is.na(params$phenomenon))
|
|
|
|
|
stop('Parameter "phenomenon" is required')
|
|
|
|
@ -37,8 +124,10 @@ parse_get_measurements_params = function (params) {
|
|
|
|
|
if (!is.null(params$boxes)) query$boxIds = paste(params$boxes$X_id, collapse = ',')
|
|
|
|
|
if (!is.null(params$bbox)) query$bbox = paste(params$bbox, collapse = ',')
|
|
|
|
|
|
|
|
|
|
if (!is.na(params$from)) query$`from-date` = date_as_isostring(params$from)
|
|
|
|
|
if (!is.na(params$to)) query$`to-date` = date_as_isostring(params$to)
|
|
|
|
|
if (!is.na(params$from))
|
|
|
|
|
query$`from-date` = utc_date(params$from) %>% date_as_isostring()
|
|
|
|
|
if (!is.na(params$to))
|
|
|
|
|
query$`to-date` = utc_date(params$to) %>% date_as_isostring()
|
|
|
|
|
if (!is.na(params$exposure)) query$exposure = params$exposure
|
|
|
|
|
if (!is.na(params$columns)) query$columns = paste(params$columns, collapse = ',')
|
|
|
|
|
|
|
|
|
|