Skip to content

Commit b4baf03

Browse files
committed
2 parents 8a0d59b + 8bc343e commit b4baf03

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

‎R/otp-download.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ otp_dl_jar <- function(path = NULL,
5252
warning("OTP2 support is in beta \n")
5353
}
5454

55-
url <- paste0(url, "/", version, "/otp-", version, "-shaded.jar")
55+
url <- paste0(url, "/", version, "/", file_name)
5656

5757
message("The OTP will be saved to ", destfile)
5858
utils::download.file(url = url, destfile = destfile, mode = "wb", quiet = quiet)

‎R/otp-isochrone-batch.R‎

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,17 @@ otp_isochrone <- function(otpcon = NA,
5353
timezone = otpcon$timezone) {
5454
# Check for OTP2
5555
if (!is.null(otpcon$otp_version)) {
56-
if (otpcon$otp_version >= 2) {
57-
stop("Isochrones are not supported by OTP v2.X")
56+
if (otpcon$otp_version >= 2.0 & otpcon$otp_version <= 2.1) {
57+
stop("Isochrones are not supported by OTP v2.0-2.1. Consider using v1.5 or v2.2+.")
58+
} else if (otpcon$otp_version >= 2.2) {
59+
message("OTP v2.2+ experimentaly supports isochrones, see https://docs.opentripplanner.org/en/v2.4.0/sandbox/TravelTime/")
60+
}
61+
}
62+
63+
# Warn about walking isochrones not being supported by OTP v2
64+
if (otpcon$otp_version >= 2.0) {
65+
if (length(mode) == 1 && mode == "WALK") {
66+
warning("Walking-only isochrones are not supported by OTP v2. You can only use \"WALK,TRANSIT\". When set to \"WALK\" OTPv2 defaults to \"WALK,TRANSIT\". See https://docs.opentripplanner.org/en/v2.4.0/sandbox/TravelTime/")
5867
}
5968
}
6069

@@ -101,25 +110,49 @@ otp_isochrone <- function(otpcon = NA,
101110
# }
102111

103112
routerUrl <- make_url(otpcon)
104-
routerUrl <- paste0(routerUrl, "/isochrone")
105-
106-
query <- list(
107-
mode = mode,
108-
date = date,
109-
time = time,
110-
maxWalkDistance = maxWalkDistance,
111-
arriveBy = arriveBy
112-
)
113-
cutoffSec <- as.list(cutoffSec)
114-
names(cutoffSec) <- rep("cutoffSec", length(cutoffSec))
115-
query <- c(query, cutoffSec)
113+
if (otpcon$otp_version <= 1.9) {
114+
routerUrl <- paste0(routerUrl, "/isochrone")
115+
} else if (otpcon$otp_version >= 2.2) {
116+
routerUrl <- paste0(sub("/otp.*", "/", routerUrl), "otp/traveltime/isochrone")
117+
}
118+
119+
if (otpcon$otp_version <= 1.9) {
120+
query <- list(
121+
mode = mode,
122+
date = date,
123+
time = time,
124+
maxWalkDistance = maxWalkDistance,
125+
arriveBy = arriveBy
126+
)
127+
cutoffSec <- as.list(cutoffSec)
128+
names(cutoffSec) <- rep("cutoffSec", length(cutoffSec))
129+
query <- c(query, cutoffSec)
130+
} else if (otpcon$otp_version >= 2.2) {
131+
query <- list(
132+
mode = mode,
133+
time = sub("(.*\\+)(\\d{2})(\\d{2})", "\\1\\2:\\3", strftime(date_time, format = "%Y-%m-%dT%H:%M:%S%z")),
134+
arriveBy = arriveBy
135+
)
136+
cutoff <- as.list(paste0("PT", cutoffSec, "S"))
137+
names(cutoff) <- rep("cutoff", length(cutoff))
138+
query <- c(query, cutoff)
139+
}
140+
116141

117142
if (!is.null(routingOptions)) {
118143
query <- c(query, routingOptions)
119144
}
120145

121146
# Send Requests
122147
urls <- build_urls(routerUrl,fromPlace, toPlace = NULL, query)
148+
if (otpcon$otp_version >= 2.2) {
149+
urls <- gsub("fromPlace", "location", urls)
150+
urls <- paste0(
151+
sub("(https?://[^?]+\\?)(.*)", "\\1", urls),
152+
gsub("\\+", "%2B",
153+
gsub(":", "%3A",
154+
sub("(https?://[^?]+\\?)(.*)", "\\2", urls))))
155+
}
123156
message(Sys.time()," sending ",length(urls)," isochrone requests using ",ncores," threads")
124157
progressr::handlers("cli")
125158
results <- progressr::with_progress(otp_async(urls, ncores, TRUE))

0 commit comments

Comments
 (0)