Request public transport connections between given points and find stations nearby using the ‘HERE Public Transit’ API.
The function connection()
allows to request public transport connections from the API. Two types of requests are provided:
connection(..., summary = FALSE)
: The public transport connections are returned as multiple sections with the same vehicle and transport mode. Each row represents a section with a detailed route geometry.connection(..., summary = TRUE)
: A summary of the connections is retrieved, where each connection is represented as one row with a unified and simplified geometry.Request available public transport connections as detailed sections:
<- connection(
connection_section origin = poi[3:4, ],
destination = poi[5:6, ],
summary = FALSE
)
The id
column corresponds to the row of the input locations (origin
and destination
) and the rank
column enumerates the alternative routes. The maximum number of alternatives can be set by the results
parameter. Each row in the returned sf
object corresponds to a route section with a transport mode in a vehicle without a transfer.
id | rank | section | departure | origin | arrival | destination | mode | category | vehicle | provider | direction | distance | duration |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 1 | 1 | 2021-01-31 13:18:00 | ORIG | 2021-01-31 13:28:00 | Lausanne, Sallaz | pedestrian | NA | NA | NA | NA | 582 | 600 |
1 | 1 | 2 | 2021-01-31 13:28:00 | Lausanne, Sallaz | 2021-01-31 13:37:00 | Lausanne, gare | subway | Metro Service | m2 | Transport publics de la Région Lausannoise | Lausanne, Ouchy-Olympique | 2940 | 540 |
1 | 1 | 3 | 2021-01-31 13:37:00 | Lausanne, gare | 2021-01-31 13:42:00 | Lausanne | pedestrian | NA | NA | NA | NA | 270 | 300 |
1 | 1 | 4 | 2021-01-31 13:44:00 | Lausanne | 2021-01-31 14:56:00 | Bern | intercityTrain | Inter Regional Rail Service | IR IR15 | Schweizerische Bundesbahnen SBB | Luzern | 97078 | 4320 |
1 | 1 | 5 | 2021-01-31 15:02:00 | Bern | 2021-01-31 15:14:00 | Kehrsatz Nord | cityTrain | Suburban Railway | S S3 | BLS AG (bls) | Belp | 8531 | 720 |
1 | 1 | 6 | 2021-01-31 15:14:00 | Kehrsatz Nord | 2021-01-31 15:16:00 | DEST | pedestrian | NA | NA | NA | NA | 103 | 120 |
Print the public transport sections on an interactive leaflet map:
if (requireNamespace("mapview", quietly = TRUE)) {
::mapview(connection_section,
mapviewzcol = "mode",
layer.name = "Transport mode",
map.types = c("Esri.WorldTopoMap"),
homebutton = FALSE
) }
Request a summary of the available public transport connections:
<- connection(
connection_summary origin = poi[3:4, ],
destination = poi[5:6, ],
summary = TRUE
)
id | rank | departure | origin | arrival | destination | transfers | modes | categories | vehicles | providers | distance | duration |
---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 1 | 2021-01-31 13:18:00 | Lausanne, Sallaz | 2021-01-31 15:16:00 | Kehrsatz Nord | 2 | pedestrian, subway, pedestrian, intercityTrain, cityTrain, pedestrian | Metro Service, Inter Regional Rail Service, Suburban Railway | m2, IR IR15, S S3 | Transport publics de la Région Lausannoise, Schweizerische Bundesbahnen SBB, BLS AG (bls) | 109504 | 6600 |
1 | 2 | 2021-01-31 13:54:00 | Lausanne, Sallaz | 2021-01-31 15:45:00 | Kehrsatz Nord | 2 | pedestrian, subway, pedestrian, intercityTrain, cityTrain, pedestrian | Metro Service, Long Distance Trains, Suburban Railway | m2, IC1, S S3 | Transport publics de la Région Lausannoise, Schweizerische Bundesbahnen SBB, BLS AG (bls) | 109504 | 6180 |
2 | 1 | 2021-01-31 13:06:00 | Basel, Kleinhüningen | 2021-01-31 15:03:00 | Zürich HB | 1 | pedestrian, lightRail, pedestrian, intercityTrain, pedestrian | Tram Service, Inter Regional Rail Service | 8, IR IR36 | Basler Verkehrsbetriebe, Schweizerische Bundesbahnen SBB | 91200 | 6900 |
2 | 2 | 2021-01-31 13:36:00 | Basel, Kleinhüningen | 2021-01-31 15:12:00 | Zürich HB | 1 | pedestrian, lightRail, pedestrian, intercityTrain, pedestrian | Tram Service, Long Distance Trains | 8, IC3 | Basler Verkehrsbetriebe, Schweizerische Bundesbahnen SBB | 97016 | 5700 |
The function station()
allows to request public transport stations nearby points of interest (POIs). The radius
defines the maximum search distance in meters and results
specifies the maximum number of returned stations. The returned sf
object contains the locations of the stations and the available public transport lines at the station.
<- station(
stations poi = poi,
radius = 500,
results = 5
)
Print the POIs, the radius and stations on an interactive leaflet map:
<-
buffer %>%
poi st_transform(2056) %>%
st_buffer(500) %>%
st_transform(4326)
if (requireNamespace("mapview", quietly = TRUE)) {
<-
m ::mapview(poi, alpha.region = 1, col.region = "black",
mapviewlabel = poi$city, layer.name = "POIs",
map.types = c("Esri.WorldTopoMap"), homebutton = FALSE) +
::mapview(stations, col.region = "yellow", alpha = 1,
mapviewlabel = stations$station, layer.name = "Stations",
homebutton = FALSE) +
::mapview(buffer, col.region = "transparent", alpha.region = 0,
mapviewlayer.name = "Buffer", homebutton = FALSE, legend = FALSE)
m }