| Title: | Calculate Travel Times Over Space |
|---|---|
| Description: | Calculate travel time over a friction surface from a specified set of locations. |
| Authors: | Gerry Ryan [aut, cre] (ORCID: <https://orcid.org/0000-0003-0183-7630>), Daniel Weiss [aut] (ORCID: <https://orcid.org/0000-0002-6175-5648>), Nicholas Tierney [ctb] (ORCID: <https://orcid.org/0000-0003-1460-8722>) |
| Maintainer: | Gerry Ryan <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-07-20 01:55:42 UTC |
| Source: | https://github.com/idem-lab/traveltime |
Calculate the travel time from a set of points over a friction surface.
calculate_travel_time( friction_surface, points, filename = NULL, overwrite = FALSE )calculate_travel_time( friction_surface, points, filename = NULL, overwrite = FALSE )
friction_surface |
A |
points |
A two-column |
filename |
|
overwrite |
|
Implements methods from Weiss et al. 2018, 2020 to calculate travel time from given locations over a friction surface.
Over large areas this function can require significant RAM and will be slow.
Pre-prepared walking or motorised friction surfaces can be obtained
with?get_friction_surface. User can also provide their own friction
surface. This surface but must be in resistance units (1/conductance), e.g.
minutes/meter. See Van Etten 2017.
Note on this implementation: as of package version 1. Earlier versions of
this package used the raster and gdistance packages. These
dependencies have been removed and now instead rely exclusively on terra
for spatial data handling. The two approaches use the same cost model
(eight-direction movement, edge cost distance * mean(friction)) and
produce effectively the same result. terra::costDist() computes true
geodesic inter-cell distances, so the new approach is more accurate than
the old gdistance's distance approximation away from the equator (the
results are identical at the equator and for projected coordinate systems).
The remaining difference is a boundary convention at the origins:
gdistance includes half of the starting cell's own friction when leaving
a point, whereas terra::costDist measures cost to the border of the
origin cells and omits it. This appears as a small, near-constant offset
(about half a cell of friction) close to the origin points. See
data-raw/costdist_migration_comparison.md in the package source for the
full comparison.
Citations:
D. J. Weiss, A. Nelson, C. A. Vargas-Ruiz, K. Gligoric, S., Bavadekar, E. Gabrilovich, A. Bertozzi-Villa, J. Rozier, H. S. Gibson, T., Shekel, C. Kamath, A. Lieber, K. Schulman, Y. Shao, V. Qarkaxhija, A. K. Nandi, S. H. Keddie, S. Rumisha, P. Amratia, R. Arambepola, E. G. Chestnutt, J. J. Millar, T. L. Symons, E. Cameron, K. E. Battle, S. Bhatt, and P. W. Gething. Global maps of travel time to healthcare facilities. (2020) Nature Medicine. https://doi.org/10.1038/s41591-020-1059-1
D. J. Weiss, A. Nelson, H.S. Gibson, W. Temperley, S. Peedell, A. Lieber, M. Hancher, E. Poyart, S. Belchior, N. Fullman, B. Mappin, U. Dalrymple, J. Rozier, T.C.D. Lucas, R.E. Howes, L.S. Tusting, S.Y. Kang, E. Cameron, D. Bisanzio, K.E. Battle, S. Bhatt, and P.W. Gething. A global map of travel time to cities to assess inequalities in accessibility in 2015. (2018). Nature. https://doi:10.1038/nature25181
van Etten, J. (2017). R package gdistance: Distances and routes on geographical grids. Journal of Statistical Software https://doi.org/10.18637/jss.v076.i13
SpatRaster
ext <- matrix( data = c("111", "0", "112", 1), nrow = 2, ncol = 2, dimnames = list( c("x", "y"), c("min", "max") ) ) friction_surface <- get_friction_surface( surface = "motor2020", extent = ext ) from_here <- data.frame( x = c(111.2, 111.9), y = c(0.2, 0.35) ) calculate_travel_time( friction_surface = friction_surface, points = from_here )ext <- matrix( data = c("111", "0", "112", 1), nrow = 2, ncol = 2, dimnames = list( c("x", "y"), c("min", "max") ) ) friction_surface <- get_friction_surface( surface = "motor2020", extent = ext ) from_here <- data.frame( x = c(111.2, 111.9), y = c(0.2, 0.35) ) calculate_travel_time( friction_surface = friction_surface, points = from_here )
SpatRaster or SpatVector
Formats spatial extent for use in get_friction_surface.
ext_from_terra(r)ext_from_terra(r)
r |
|
2x2 matrix
library(terra) r <- terra::rast( extent = terra::ext(c(111, 112, 0, 1)) ) ext_from_terra(r)library(terra) r <- terra::rast( extent = terra::ext(c(111, 112, 0, 1)) ) ext_from_terra(r)
This function allows get_friction_surface() to accept the argument extent as a vector, 2x2 matrix, SpatVector, or SpatRaster and extracts and converts into the annoyingly specific format necessary to download the friction surface. See details in ?get_friction_surface
ext_matrix(extent)ext_matrix(extent)
extent |
|
2x2 matrix with column names "x" and "y" and row names "min"
and "max"
# vector/double x <- c(111, 112, 0, 1) ext_matrix(x) # SpatExtent y <- terra::ext(x) ext_matrix(y) # SpatRaster r <- terra::rast(extent = y) ext_matrix(r) # SpatVector v <- terra::vect(y) ext_matrix(v)# vector/double x <- c(111, 112, 0, 1) ext_matrix(x) # SpatExtent y <- terra::ext(x) ext_matrix(y) # SpatRaster r <- terra::rast(extent = y) ext_matrix(r) # SpatVector v <- terra::vect(y) ext_matrix(v)
Extent vector to matrix
ext_vect_to_matrix(x)ext_vect_to_matrix(x)
x |
|
2x2 matrix
ext_vect_to_matrix(c(111,112,0, 1))ext_vect_to_matrix(c(111,112,0, 1))
Wrapper function to download friction surfaces via
malariaAtlas::getRaster().
get_friction_surface( surface = c("motor2020", "walk2020"), filename = NULL, overwrite = FALSE, extent = NULL )get_friction_surface( surface = c("motor2020", "walk2020"), filename = NULL, overwrite = FALSE, extent = NULL )
surface |
|
filename |
|
overwrite |
Overwrite |
extent |
Spatial extent as one of:
See details |
Convenience wrapper to malariaAtlas::getRaster() to access
motorised and walking travel friction layers per Weiss et al. 2020, that
adds safety to check existing files before download. Surfaces can be
downloaded directly from:
https://malariaatlas.org/project-resources/accessibility-to-healthcare/.
Here —
surface = "motor2020" will download
"Explorer__2020_motorized_friction_surface", and
surface = "walk2020" will download
"Explorer__2020_walking_only_friction_surface".
D. J. Weiss, A. Nelson, C. A. Vargas-Ruiz, K. Gligoric, S., Bavadekar, E. Gabrilovich, A. Bertozzi-Villa, J. Rozier, H. S. Gibson, T., Shekel, C. Kamath, A. Lieber, K. Schulman, Y. Shao, V. Qarkaxhija, A. K. Nandi, S. H. Keddie, S. Rumisha, P. Amratia, R. Arambepola, E. G. Chestnutt, J. J. Millar, T. L. Symons, E. Cameron, K. E. Battle, S. Bhatt, and P. W. Gething. Global maps of travel time to healthcare facilities. (2020) Nature Medicine. https://doi.org/10.1038/s41591-020-1059-1
extent is formatted and then passed through to
malariaAtlas::getRaster() as a 2x2 matrix. It is converted into a matrix
using ext_matrix. The matrix format used is as returned by
sf::st_bbox() — the first column has the minimum, the second the
maximum values; rows 1 & 2 represent the x & y dimensions respectively:
matrix(c("xmin", "ymin", "xmax", "ymax"), nrow = 2, ncol = 2, dimnames = list(c("x", "y"), c("min", "max"))). NULL extent downloads (large)
global layer.
Troubleshooting: if you get a warning Failed to connect to MAP geoserver,
this is an issue with fetching the friction surface using
malariaAtlas::getRaster, and not an issue with traveltime itself. The
server may be down or there may be an issue with that package.
SpatRaster
# for more examples of passing exten types see ?ext_matrix ext <- c(111, 112, 0, 1) get_friction_surface( surface = "motor2020", extent = ext )# for more examples of passing exten types see ?ext_matrix ext <- c(111, 112, 0, 1) get_friction_surface( surface = "motor2020", extent = ext )
Locations of all MRT and LRT station exits in Singapore.
stationsstations
stations A data frame with 563 rows and 2 columns:longitude
latitude
Land Transport Authority. (2019). LTA MRT Station Exit (GEOJSON) (2024) Dataset. data.gov.sg. Retrieved December 10, 2024 from https://data.gov.sg/datasets/d_b39d3a0871985372d7e1637193335da5/view