With TargomoR you can access routing data all over the world in a convenient, nested structure, letting you focus on the start and end points. Visualising a route can add the finishing touch to a map or shiny application!

Getting the Data

For the routing service, getTargomoRoutes() returns a named nested list. The names are the travel modes given in the travelType option (specifying multiple modes will make multiple calls to the API).

Within each travel mode is a list of the returned routes - one for each source/target combination where a route has been found. Each route is a data.frame, containing the source and target IDs, and a features data.frame of a simple feature collection (class ‘sf’). This contains:

  • points - the source and target points of the route, as POINT objects.
  • walk, bike, car, transit - the routes by each mode of transport (where requested) as LINESTRING objects.
  • transfers - points where public transport changes (e.g. change bus) as POINT objects.

Each SFC also contains fields giving the start and end names of the LINESTRINGs, the length of time the section takes and the distance in metres.

For example, for two routes by bike, the output will look like:

The features object for the first route will look like:

Integration with Leaflet

The TargomoR package lets you easily visualise your route data. You can either:

In this example, we use addTargomoRoutes() to show the cycling routes above.

Drawing Options

Using addTargomoRoutes() or drawTargomoRoutes() you can customise the way the routes appear on the map with a call to routeDrawOptions(). The options available are:

Option Default Meaning
showMarkers TRUE Should the source/target points be marked?
showTransfers TRUE Should the public transport changes be marked?
{travel}Color car = "blue", bike = "orange", walk = "green", transit = "red" The route line color
{travel}Weight 5 for all travel types The route line width
{travel}DashArray walk = "1,10", other = NULL The route dash pattern
transferColor "blue" The color for transfer circle markers
transferRadius 10 The radius for transfer circle markers

Changing these, we could for instance make the map above but with purple dotted lines (and here we’ll use drawTargomoRoutes()):