Learn R Programming

spatialEco (version 0.1-5)

land.metrics: Landscape metrics for points and polygons

Description

Calculates a variety of landscape metrics, on binary rasters, for polygons or points with a buffer distance

Usage

land.metrics(x, y, bkgd = NA, metrics = c(4, 14, 33, 34, 35, 37, 38), bw = 1000, latlon = FALSE, trace = TRUE)

Arguments

x
SpatalPointsDataFrame or SpatalPolgonsDataFrame class object
y
raster class object
bkgd
Background value (will be ignored)
metrics
Numeric index of desired metric (see available metrics)
bw
Buffer distance (ignored if x is SpatalPolgonsDataFrame)
latlon
Is raster data in lat-long (TRUE/FALSE)
trace
Plot raster subsets and echo object ID at each iteration (TRUE | FALSE)

Value

If multiple classes are evaluated a list object with a data.frame for each class contaning specified metrics in columns. The data.frame is ordered and shares the same row.names as the input feature class and can be directly joined to the @data slot. For single class problems a data.frame object is returned.

Examples

Run this code
 library(raster)
 library(sp)

 r <- raster(nrows=180, ncols=360, xmn=571823.6, xmx=616763.6, ymn=4423540, 
             ymx=4453690, resolution=270, crs = CRS("+proj=utm +zone=12 +datum=NAD83 
             +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"))

 r[] <- rpois(ncell(r), lambda=1)
 r <- calc(r, fun=function(x) { x[x >= 1] <- 1; return(x) } )  
 x <- sampleRandom(r, 10, na.rm = TRUE, sp = TRUE)

 ( class.1 <- land.metrics(x=x, y=r, bw=1000, bkgd = 0, metrics = c(4,7,33,34)) )
 ( all.class <- land.metrics(x=x, y=r, bw=1000, bkgd = NA, metrics = c(4,7,33,34)) )

 # Pull metrics associated with class "0"
 all.class[["0"]]

Run the code above in your browser using DataLab