gdistance: Distances and Routes on Geographical Grids


gdistance provides classes and functions to calculate various distance measures and routes in heterogeneous geographic spaces represented as grids. Least-cost distances as well as more complex distances based on (constrained) random walks can be calculated. Also the corresponding routes or probabilities of passing each cell can be determined. The package implements classes to store the data about the probability or cost of transitioning from one cell to another on a grid in a memory-efficient sparse format. These classes make it possible to manipulate the values of cell-to-cell movement directly, which offers flexibility and the possibility to use asymmetric values. The novel distances implemented in the package are used in geographical genetics (applying circuit theory), but may also have applications in other fields of geospatial analysis.


The package may be installed from CRAN via


The development version can be installed via


Going further

The full functionality of gdistance is illustrated in the package vignette. The vignette can be found on the package website or from within R once the package has been installed, e.g. via

vignette("Overview", package = "gdistance")