CreateDistMatrix: Create a Distance Matrix Between Two Spatial Objects

View source: R/gridandmat.R

CreateDistMatrixR Documentation

Create a Distance Matrix Between Two Spatial Objects

Description

This function creates a distance matrix between two spatial objects (sp or sf objects).

Usage

CreateDistMatrix(knownpts, unknownpts, bypassctrl = FALSE, longlat = TRUE)

Arguments

knownpts

sp or sf object; rows of the distance matrix.

unknownpts

sp or sf object; columns of the distance matrix.

bypassctrl

logical; bypass the distance matrix size control (see Details).

longlat

logical; if FALSE, Euclidean distance, if TRUE Great Circle (WGS84 ellipsoid) distance.

Details

The function returns a full matrix of distances in meters. If the matrix to compute is too large (more than 100,000,000 cells, more than 10,000,000 origins or more than 10,000,000 destinations) the function sends a confirmation message to warn users about the amount of RAM mobilized. Use bypassctrl = TRUE to skip this control.

Value

A distance matrix, row names are knownpts row names, column names are unknownpts row names.

See Also

CreateGrid

Examples

# Create a grid of paris extent and 200 meters
# resolution
data(hospital)
mygrid <- CreateGrid(w = paris, resolution = 200, returnclass = "sf")
# Create a distance matrix between known hospital and mygrid
mymat <- CreateDistMatrix(knownpts = hospital, unknownpts = mygrid, 
                          longlat = FALSE)
mymat[1:5,1:5]
nrow(paris)
nrow(mygrid)
dim(mymat)

SpatialPosition documentation built on Sept. 14, 2023, 5:07 p.m.