batch | R Documentation |
Note: set CYCLESTREETS_BATCH
, CYCLESTREETS_PW
and CYCLESTREETS_PW
environment variables, e.g. with usethis::edit_r_environ()
before trying this.
batch(
desire_lines = NULL,
id = NULL,
directory = tempdir(),
wait = FALSE,
wait_time = NULL,
name = "Batch job",
serverId = 21,
strategies = "quietest",
bothDirections = 0,
minDistance = 50,
maxDistance = 5000,
filename = "test",
includeJsonOutput = 1,
emailOnCompletion = "you@example.com",
username = Sys.getenv("CYCLESTREETS_UN"),
password = Sys.getenv("CYCLESTREETS_PW"),
base_url = "https://api.cyclestreets.net/v2/batchroutes.createjob",
pat = Sys.getenv("CYCLESTREETS_BATCH"),
silent = TRUE,
delete_job = TRUE,
cols_to_keep = c("id", "name", "provisionName", "distances", "time", "quietness",
"gradient_smooth"),
segments = TRUE
)
desire_lines |
Geographic desire lines representing origin-destination data |
id |
int Batch job ID, as returned from batchroutes.createjob. action string (start|pause|continue|terminate) Action to take. Available actions are: start: Start (open) job pause: Pause job continue: Continue (re-open) job terminate: Terminate job and delete data |
directory |
Where to save the data? |
wait |
Should the process block your R session but return a route? FALSE by default. |
wait_time |
How long to wait before getting the data in seconds?
NULL by default, meaning it will be calculated by the private function
|
name |
The name of the batch routing job for CycleStreets |
serverId |
The server ID to use (21 by default) |
strategies |
Route plan types, e.g. |
bothDirections |
int (1|0) Whether to plan in both directions, i.e. A-B as well as B-A. 0, meaning only one way routes, is the default in the R default. |
minDistance |
Min Euclidean distance of routes to be calculated |
maxDistance |
Maximum Euclidean distance of routes to be calculated |
filename |
Character string |
includeJsonOutput |
int (1|0) Whether to include a column in the resulting CSV data giving the full JSON output from the API, rather than just summary information like distance and time. |
emailOnCompletion |
Email on completion? |
username |
string Your CycleStreets account username. In due course this will be replaced with an OAuth token. |
password |
string Your CycleStreets account password. You can set it with Sys.setenv(CYCLESTREETS_PW="xxxxxx") |
base_url |
The base url from which to construct API requests (with default set to main server) |
pat |
The API key used. By default this uses |
silent |
Logical (default is FALSE). TRUE hides request sent. |
delete_job |
Delete the job? TRUE by default to avoid clogged servers |
cols_to_keep |
Columns to return in output sf object |
segments |
logical, return segments TRUE/FALSE/"both" |
See https://www.cyclestreets.net/journey/batch/ for web UI.
Recommneded max batch size: 300k routes
if(FALSE) {
library(sf)
desire_lines = od::od_to_sf(od::od_data_df, od::od_data_zones)[4:5, 1:3]
u = paste0("https://github.com/cyclestreets/cyclestreets-r/",
"releases/download/v0.5.3/od-longford-10-test.Rds")
desire_lines = readRDS(url(u))
routes_id = batch(desire_lines, username = "robinlovelace", wait = FALSE)
# Wait for some time, around a minute or 2
routes_wait = batch(id = routes_id, username = "robinlovelace", wait = TRUE, delete_job = FALSE)
names(routes_wait)
plot(routes_wait)
plot(desire_lines$geometry[4])
plot(routes_wait$geometry[routes_wait$route_number == "4"], add = TRUE)
head(routes_wait$route_number)
unique(routes_wait$route_number)
# Job is deleted after this command:
routes_attrib = batch(desire_lines, id = routes_id, username = "robinlovelace", wait = TRUE)
names(routes_attrib)
unique(routes_attrib$route_number)
desire_lines_huge = desire_lines[sample(nrow(desire_lines), 250000, replace = TRUE), ]
routes_id = batch(desire_lines_huge, username = "robinlovelace", wait = FALSE)
names(routes)
plot(routes$geometry)
plot(desire_lines$geometry, add = TRUE, col = "red")
routes = batch(desire_lines, username = "robinlovelace", wait_time = 5)
# profvis::profvis(batch_read("test-data.csv.gz"))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.