Learn R Programming

terra (version 0.2-8)

gridDistance: Distance on a grid

Description

The function calculates the distance to cells on a raster when the path has to go through the centers of neighboring cells. Distances are computed by summing local distances between cells, which are connected with their neighbours in 8 directions ('queen' case).

In future versions, the distance is expressed in meters if the coordinate reference system (CRS) is longitude/latitude (+proj=longlat) and in the units of the CRS (typically meters) in other cases.

Usage

# S4 method for SpatRaster
gridDistance(x, filename="", overwrite=FALSE, wopt=list(), ...)

Arguments

x

SpatRaster

filename

character. Output filename. Optional

overwrite

logical. If TRUE, filename is overwritten

wopt

list. Options for writing files as in writeRaster

...

Additional arguments. None implemented

Value

SpatRaster

Examples

Run this code
# NOT RUN {
r <- rast(ncol=10, nrow=10)
v <- rep(NA, 100)
v[23] <- 1
values(r) <- v
g <- gridDistance(r)
# }

Run the code above in your browser using DataLab