Learn R Programming

raster (version 1.9-44)

gridDistance: Grid distance

Description

The function calculates the distance to cells of a RasterLayer when the path has to follow the center of neighboring raster cells (currently only implemented as a 'queen' case). The distance is in meters if the RasterLayer is not projected (+proj=longlat) and in map units (typically meters) when it is projected. Distances are calculated by summing local distances between cells, which are connected with their neighbours in 8 directions.

Usage

gridDistance(x, origin, omit=NULL, filename="", ...)

Arguments

x
a RasterLayer object
origin
value(s) of the cells from which the distance is calculated
omit
value(s) of the cells which cannot be traversed (optional)
filename
character. output filename (optional)
...
Additional arguments as for writeRaster

Value

  • A RasterLayer object

Details

If the RasterLayer to be processed is big, it will be processed in chunks automatically. This may lead to errors in the case of complex objects spread over different chunks (meandering rivers, for instance). You can try to solve these issues by varying the chunk size, see function setOptions().

See Also

See distance for 'as the crow flies' distance. Additional distance measures and options (directions, cost-distance) are available in the 'gdistance' package.

Examples

Run this code
#world lonlat raster
r <- raster(ncol=10,nrow=10)
r[] <- 1
r[48] <- 2
r[66:68] <- 3
d <- gridDistance(r,origin=2,omit=3) 
plot(d)

#UTM small area
projection(r) <- "+proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"
d <- gridDistance(r,origin=2,omit=3) 
plot(d)

Run the code above in your browser using DataLab