raster (version 1.1.7)

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(object, originValue, omitValue, filename, ...)

Arguments

object
a RasterLayer object
originValue
value of the cells from which the distance is calculated
omitValue
value of the cells which cannot be traversed
filename
character. output filename
...
additional arguments. See Details.

Value

  • A RasterLayer object

Details

The following additional arguments can be passed, to replace default values for this function rll{ overwrite Logical. If TRUE, "filename" will be overwritten if it exists format Character. Output file type. See writeRaster datatype Character. Output data type. See dataType progress Character. Valid values are "text", "tcltk", "windows" (on that platform only) and "" }

See Also

For more options (directions, cost-distance) see the gdistance package on R-forge

Examples

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

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

Run the code above in your browser using DataCamp Workspace