Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions R/vl_isochrone.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#' (see \url{https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#costing-options}
#' for more details about the options available for each costing model).
#' @param server URL of the Valhalla server.
#' @param request_options list of request options
#' (see \url{https://valhalla.github.io/valhalla/api/isochrone/api-reference/#other-request-parameters}).
#' @returns An sf MULTIPOLYGON object is returned with the following fields:
#' 'metric' (the metric used, either 'time' or 'distance')
#' and 'contour' (the value of the metric).
Expand All @@ -51,7 +53,8 @@
#' @export
vl_isochrone <- function(loc, times, distances,
costing = "auto", costing_options = list(),
server = getOption("valh.server")) {
server = getOption("valh.server"),
request_options = list()) {
# Handle input point(s)
loc <- input_route(x = loc, single = TRUE, id = "loc")
oprj <- loc$oprj
Expand Down Expand Up @@ -86,13 +89,33 @@ vl_isochrone <- function(loc, times, distances,
stop("You must provide either 'times' or 'distances'.", call. = FALSE)
}

# Warn users if they provided something in request_options that we override
if (is.list(request_options) && length(request_options) > 0) {
if ("costing" %in% names(request_options)) {
warning("The 'costing' parameter in 'request_options' will be ignored, as it is set by the 'costing' argument of the function.", call. = FALSE)
}
if ("costing_options" %in% names(request_options)) {
warning("The 'costing_options' parameter in 'request_options' will be ignored, as it is set by the 'costing_options' argument of the function.", call. = FALSE)
}
if ("locations" %in% names(request_options)) {
warning("The 'locations' parameter in 'request_options' will be ignored, as it is set by the 'loc' argument of the function.", call. = FALSE)
}
if ("polygons" %in% names(request_options)) {
warning("The 'polygons' parameter in 'request_options' will be ignored, as it is set to TRUE in the function.", call. = FALSE)
}
if ("contours" %in% names(request_options)) {
warning("The 'contours' parameter in 'request_options' will be ignored, as it is set by the 'times' or 'distances' argument of the function.", call. = FALSE)
}
}

# Build the JSON argument of the request
json <- list(
json <- c(list(
costing = costing,
polygons = TRUE,
contours = contours,
locations = locs
)
), request_options)

if (is.list(costing_options) && length(costing_options) > 0) {
json$costing_options <- list()
json$costing_options[[costing]] <- costing_options
Expand Down
21 changes: 18 additions & 3 deletions R/vl_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#' (see \url{https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#costing-options}
#' for more details about the options available for each costing model).
#' @param server URL of the Valhalla server.
#' @param request_options list of request options
#' (see \url{https://valhalla.github.io/valhalla/api/matrix/api-reference/#other-request-options}).
#' @return
#' The output of this function is a list composed of one or two matrices
#' and 2 data.frames
Expand Down Expand Up @@ -81,7 +83,8 @@
#' @export
vl_matrix <- function(src, dst, loc,
costing = "auto", costing_options = list(),
server = getOption("valh.server")) {
server = getOption("valh.server"),
request_options = list()) {
# Handle input points
if (!missing(loc)) {
dst_r <- src_r <- input_table(x = loc, id = "loc")
Expand All @@ -92,13 +95,25 @@ vl_matrix <- function(src, dst, loc,
sources <- lapply(seq_along(src_r$lon), function(i) list(lon = src_r$lon[i], lat = src_r$lat[i]))
targets <- lapply(seq_along(dst_r$lon), function(i) list(lon = dst_r$lon[i], lat = dst_r$lat[i]))

# Warn users if they provided something in request_options that we override
if (is.list(request_options) && length(request_options) > 0) {
if (any(names(request_options) %in% c("costing", "sources", "targets", "verbose"))) {
warning(paste0(
"You provided some parameters in 'request_options' (among 'costing', 'costing_options', 'sources', 'targets' or 'verbose')",
" that are overridden by the function arguments. ",
"Please provide these parameters directly as function arguments instead of in 'request_options'."
), call. = FALSE)
}
}

# Build the JSON argument of the request
json <- list(
json <- c(list(
costing = costing,
sources = sources,
targets = targets,
verbose = TRUE
)
), request_options)

if (is.list(costing_options) && length(costing_options) > 0) {
json$costing_options <- list()
json$costing_options[[costing]] <- costing_options
Expand Down
21 changes: 18 additions & 3 deletions R/vl_route.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#' (see \url{https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#costing-options}
#' for more details about the options available for each costing model).
#' @param server URL of the Valhalla server.
#' @param request_options list of request options
#' (see \url{https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#other-request-options}).
#' @return
#' The output of this function is an sf LINESTRING of the shortest route.\cr
#' It contains 4 fields: \itemize{
Expand Down Expand Up @@ -83,7 +85,8 @@
#' @export
vl_route <- function(src, dst, loc,
costing = "auto", costing_options = list(),
server = getOption("valh.server")) {
server = getOption("valh.server"),
request_options = list()) {
# Handle input points
if (missing(loc)) {
# From src to dst
Expand All @@ -105,11 +108,23 @@ vl_route <- function(src, dst, loc,
locs <- lapply(seq_along(loc$lon), function(i) list(lon = loc$lon[i], lat = loc$lat[i]))
}

# Warn users if they provided something in request_options that we override
if (is.list(request_options) && length(request_options) > 0) {
if (any(names(request_options) %in% c("locations", "costing", "costing_options"))) {
warning(paste0(
"You provided some parameters in 'request_options' (among 'locations', 'costing' or 'costing_options')",
" that are overridden by the function arguments. Please remove these parameters",
" from 'request_options' to avoid confusion."
), call. = FALSE)
}
}

# Build the JSON argument of the request
json <- list(
json <- c(list(
costing = costing,
locations = locs
)
), request_options)

if (is.list(costing_options) && length(costing_options) > 0) {
json$costing_options <- list()
json$costing_options[[costing]] <- costing_options
Expand Down
6 changes: 5 additions & 1 deletion man/vl_isochrone.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/vl_matrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/vl_route.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.