Traffic API

Traffic flow and incident information based on the ‘HERE Traffic’ API. The traffic flow data contains speed ("SP") and congestion (jam factor: "JF") information. Traffic incidents contain information about location, time, duration, severity, description and other details.

Flow

In order to request the traffic flow, areas of interest (AOIs) have to be provided. The AOIs must be an sf object containing a polygon or multiple polygons. The response from the HERE Traffic API will be spatially joined on the AOIs and thereby the traffic flows are mapped to the corresponding polygon. The optional time interval, which defines the traffic flow that should be considered, can be specitified by the from_dt and to_dt parameters. The datetime information passed to the function must be a timestamp of type POSIXct, POSIXt.

flow <- traffic(
  aoi = aoi[aoi$code == "LI", ],
  product = "flow",
  from_dt = Sys.time() - (60*60*2),
  to_dt = Sys.time()
)

Print the (ordered) ‘jam factor’ of the traffic flow on an interactive leaflet map:

flow <- flow[order(flow$JF), ]
mapview(flow,
        zcol = "JF",
        lwd = flow$JF*2,
        layer.name = "Jam factor",
        map.types = c("Esri.WorldTopoMap"),
        homebutton = FALSE
)

Incidents

AOIs also must be provided in order to request information about traffic incidents in specific regions. The time interval of interest is provided equally as described above for the traffic flow request. The local_time parameter defines if the time values in the response for traffic incidents should be in the local time of the incident or in UTC (default).

incidents <- traffic(
  aoi = aoi[aoi$code == "LI", ],
  product = "incidents",
  from_dt = Sys.time()-60*60*1.5,
  local_time = FALSE
)

Print the traffic incidents on an interactive leaflet map:

mapview(incidents,
        zcol = "type",
        layer.name = "Incident type",
        map.types = c("Esri.WorldTopoMap"),
        homebutton = FALSE
)

API Reference