Learn R Programming

geospacom (version 0.5-8)

DistanceMatrix: Computes distance matrices

Description

Computes a distance matrix from a given set of polygons (SpatialPolygonsDataFrame)

Usage

DistanceMatrix(poly, id, unit = 1000, longlat = TRUE, fun = distHaversine)

Arguments

id
The id used to as area ids
unit
meters per unit in the distance matrix. The default unit = 1000 outputs a distance matrix in kilometres, in most of the cases. With different type of projections unit can be used to properly calibrate the metric unit.
longlat
if TRUE indicates that the distance is calculated using longitude and latitude coordinates and a spherical distance functions (to be used with CRS GPS). If FALSE, the distance is computed as the euclidean distance on the flat projection (to be used with CRS CH1903). Default is TRUE.
fun
A function to compute distances with longitude and latitude coordinates (e.g., distCosine, distHaversine, distVincenty*) to be passed to distm. It works only if longlat=TRUE

Value

A square distance matrix

Examples

Run this code
## load the CRS projection definition and a shape file
data(CH1903)
## Not run: 
#   yu.reg <- ReadPoly("path/to/my/shapefile.shp", proj = CH1903)
# 
# 
# data(yu.reg)
# names(yu.reg) <- "area.name"
# d.geo <- DistanceMatrix(yu.reg, "area.name", longlat = FALSE)
# ## End(Not run)

Run the code above in your browser using DataLab