Learn R Programming

TargomoR

Overview

The TargomoR package provides an R interface to the Targomo REST API. Use TargomoR to get real travel-time information:

Isochrone Polygons: visualise what ‘half an hour away’ really looks like, using public transport, driving, cycling or walking.

Travel Routes: visualise up-to-date routing data quickly and simply, with pre-written methods for adding complex data to leaflet maps.

Point-to-Point Times: get travel-time data for a large array of source and target points, in a tidy format ready to feed into further analysis.

Note

This package is being developed with the permission of Targomo, but is not an official product. For more information about Targomo, please see their website, and be aware of their terms and conditions.

See below for information on installing the package, setting up your environment correctly, and using the package.

Installation

TargomoR is not yet on CRAN. To install this development version from GitHub please use:

remotes::install_github("cwthom/TargomoR")
library(TargomoR)

Set Up Environment

The functions in TargomoR all rely on having a Targomo API Key. To get yours, please sign up with Targomo.

You’ll also need to know what region of the world to use. For example if you’re looking for travel-time information in Germany, your region is “westcentraleurope”. Find your region. In the examples on this page the region is “britishisles”.

You can pass these variables to each function manually if you like, but to avoid this, the functions will default to use the TARGOMO_API_KEY and TARGOMO_REGION environment variables respectively.

To take advantage of this, you can set these variables in an .Renviron file. Use the following snippet to write the variables to the file.

setTargomoVariables(api_key = "<YOUR KEY>", region = "<YOUR REGION>",
                    global = FALSE)

# global = TRUE  will write to .Renviron at Sys.getenv("HOME")
# global = FALSE will write to .Renviron at getwd()

Restart R for these variables to take effect.

Get Travel Time Data

You’re now ready to use Targomo to get travel-time and routing data. There are three services currently supported:

For each service there are 3 core functions:

  • getTargomo{service} - returns an sf object containing the requested data.
  • drawTargomo{service} - draws the resultant object on a leaflet map.
  • addTargomo{service} - combines get-ting and draw-ing into a single call.

The draw* and add* functions are provided as a convenience - feel free to create your own drawing functions to put the data onto a map!

There is also support for adding basemaps through addTargomoTiles(). See the vignette on basemaps for more information.

You can also check the capabilities of your Targomo account with getTargomoCapabilities().

Attribution

It’s a condition of use of the Targomo services that you attribute the travel time data to them. Full details can be found on their attributions page. To help with this there are two functions in TargomoR:

  • attributionLink - just returns the URL of the attributions page
  • addTargomoAttribution - adds the attribution iframe to a leaflet control, for use with leaflet maps.

It is your responsibility to make sure you comply with the attribution requirements appropriate to your plan.

Contributing

Please note that the ‘TargomoR’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.


Logo

Copy Link

Version

Install

install.packages('TargomoR')

Monthly Downloads

11

Version

0.2.0

License

GPL-3

Maintainer

Chris Mason-Thom

Last Published

December 6th, 2019

Functions in TargomoR (0.2.0)

draw-routes

Draw Routes
timeDrawOptions

Options for Drawing Times on the Map
getTargomoMapURL

Targomo Map Tiles URL
getTargomoPolygons

Add Targomo Polygons to a Leaflet Map
createRequestURL

Create Request URL
timeLegendOptions

Time Legend Options
processCapabilities

Process Capabilities
routes

Add Targomo Routes to a Leaflet Map
messageMultipleTravelModes

Message if multiple Travel Modes supplied
routeDrawOptions

Options for Drawing Routes on the Map
process

Process API responses
polygonDrawOptions

Options for Drawing Polygons on the Map
%>%

Pipe operator
times

Add Targomo Times to a Leaflet Map
setTargomoVariables

Set Targomo Environment Variables
targomoAPI

Targomo API base URL
tidy-capabilities

Helper functions for tidying up capabilities response
options

Set Targomo Options
formatting

Format Edgeweights (times and distances)
tiles

Add Targomo Basemaps to a Leaflet Map
callTargomoAPI

Call the Targomo API
createRequestBody

Create Request Body
createRoutePopup

Create Route Popups
addTimeLegend

Add Time Legend to Map
deriveOptions

Derive Options
capabilities

Get Account Capabilities
createTimePalette

Create a Colour Palette for Time Service Results
attribution

Add Targomo Attributions
deriveSources

Derive Sources/Targets