2017-08-14 18:10:16 +02:00
|
|
|
# ==============================================================================
|
|
|
|
#
|
2017-08-13 16:07:24 +02:00
|
|
|
#' Convert a \code{sensebox} or \code{osem_measurements} dataframe to an
|
|
|
|
#' \code{\link[sf]{st_sf}} object.
|
|
|
|
#'
|
|
|
|
#' @param x The object to convert
|
|
|
|
#' @param ... maybe more objects to convert
|
|
|
|
#' @return The object with an st_geometry column attached.
|
|
|
|
#' @export
|
|
|
|
osem_as_sf = function (x, ...) {
|
|
|
|
sf::st_as_sf(x, ..., coords = c('lon', 'lat'), crs = 4326)
|
|
|
|
}
|
|
|
|
|
2017-08-14 18:10:16 +02:00
|
|
|
# parses from/to params for get_measurements_ and get_boxes_
|
2017-08-12 15:17:47 +02:00
|
|
|
parse_dateparams = function (from, to) {
|
|
|
|
from = utc_date(from)
|
|
|
|
to = utc_date(to)
|
2017-08-23 14:23:17 +02:00
|
|
|
if (from - to > 0) stop('"from" must be earlier than "to"')
|
2017-08-12 15:17:47 +02:00
|
|
|
c(date_as_isostring(from), date_as_isostring(to))
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: cannot handle mixed vectors of POSIXlt and POSIXct
|
|
|
|
utc_date = function (date) {
|
|
|
|
time = as.POSIXct(date)
|
|
|
|
attr(time, 'tzone') = 'UTC'
|
|
|
|
time
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: cannot handle mixed vectors of POSIXlt and POSIXct
|
2017-08-14 18:10:16 +02:00
|
|
|
date_as_isostring = function (date) format.Date(date, format = '%FT%TZ')
|