Public Transit API

Request public transport connections between given points and find stations nearby using the ‘HERE Public Transit’ API.

Connections

The function connection() allows to request public transport connections from the API. Two types of requests are provided:

1. Sections

Request available public transport connections as detailed sections:

connection_section <- connection(
  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 departure origin arrival destination mode category vehicle provider direction distance duration
1 1 2020-10-19 23:54:00 ORIG 2020-10-20 00:04:00 Lausanne, Sallaz pedestrian NA NA NA NA 582 600
1 1 2020-10-20 00:04:00 Lausanne, Sallaz 2020-10-20 00:13:00 Lausanne, gare subway Train m2 Transport publics de la Région Lausannoise Lausanne, Ouchy-Olympique 2940 540
1 1 2020-10-20 00:13:00 Lausanne, gare 2020-10-20 00:18:00 Lausanne pedestrian NA NA NA NA 300 300
1 1 2020-10-20 00:20:00 Lausanne 2020-10-20 01:26:00 Bern intercityTrain Intercity Train IC 1 Schweizerische Bundesbahnen SBB Zürich HB 97091 3960
1 1 2020-10-20 01:32:00 Bern 2020-10-20 01:44:00 Kehrsatz Nord cityTrain Train S 3 BLS AG (bls) Belp 8668 720
1 1 2020-10-20 01:44:00 Kehrsatz Nord 2020-10-20 01:45:00 DEST pedestrian NA NA NA NA 76 60

Print the public transport sections on an interactive leaflet map:

mapview(connection_section,
        zcol = "mode",
        layer.name = "Transport mode",
        map.types = c("Esri.WorldTopoMap"),
        homebutton = FALSE
)

2. Summary

Request a summary of the available public transport connections:

connection_summary <- connection(
  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 2020-10-19 23:54:00 Lausanne, Sallaz 2020-10-20 01:45:00 Kehrsatz Nord 2 pedestrian, subway, pedestrian, intercityTrain, cityTrain, pedestrian Train, Intercity Train, Train m2, IC 1, S 3 Transport publics de la Région Lausannoise, Schweizerische Bundesbahnen SBB, BLS AG (bls) 109657 6180
1 2 2020-10-20 00:18:00 Lausanne, Sallaz 2020-10-20 02:24:00 Kehrsatz Nord 2 pedestrian, subway, pedestrian, intercityTrain, cityTrain, pedestrian Train, Intercity Train, Train m2, IR 15, S 44 Transport publics de la Région Lausannoise, Schweizerische Bundesbahnen SBB, BLS AG (bls) 109657 6480
2 1 2020-10-19 23:39:00 Basel, Kleinhüningen 2020-10-20 01:39:00 Zürich HB 1 pedestrian, lightRail, pedestrian, intercityTrain, pedestrian Tram, Intercity Train 8, IR 36 Basler Verkehrsbetriebe, Schweizerische Bundesbahnen SBB 94848 7020
2 2 2020-10-19 23:54:00 Basel, Kleinhüningen 2020-10-20 01:47:00 Zürich HB 2 pedestrian, lightRail, pedestrian, intercityTrain, intercityTrain, pedestrian Tram, Intercity Train, Intercity Train 8, IC 61, IC 1 Basler Verkehrsbetriebe, Schweizerische Bundesbahnen SBB, Schweizerische Bundesbahnen SBB 108350 6240

Stations

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.

stations <- station(
  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)

m <-
  mapview(poi, alpha.region = 1, col.region = "black",
          label = poi$city, layer.name = "POIs",
          map.types = c("Esri.WorldTopoMap"), homebutton = FALSE) +
  mapview(stations, col.region = "yellow", alpha = 1,
          label = stations$station, layer.name = "Stations",
          homebutton = FALSE) +
  mapview(buffer, col.region = "transparent", alpha.region = 0,
          layer.name = "Buffer", homebutton = FALSE, legend = FALSE)
m

API Reference