Learn R Programming

GeNetIt (version 0.1-6)

node.statistics: raster statistics for nodes

Description

returns raster value or statistics (based on specified radius) for node

Usage

node.statistics(x, r, buffer = NULL, stats = c("min", "median", "max"))

Value

data.frame object of at-node raster values or statistics

Arguments

x

sp class SpatialPointsDataFrame object

r

A rasterLayer, rasterStack or rasterBrick object

buffer

Buffer distance, radius in projection units

stats

Statistics to calculate. If vectorized, can pass a custom statistic function.

Author

Jeffrey S. Evans <jeffrey_evans@tnc.org> and Melanie A. Murphy <melanie.murphy@uwyo.edu>

Examples

Run this code
# \donttest{
 library(sf)
 library(terra)  

 data(ralu.site)
 xvars <- rast(system.file("extdata/covariates.tif", package="GeNetIt"))
   
 skew <- function(x, na.rm = TRUE) {  
           if (na.rm) x <- x[!is.na(x)]
           sum( (x - mean(x)) ^ 3) / ( length(x) * sd(x) ^ 3 )  
 		}

 # without buffer (values at point)
 system.time( {		
  stats <- node.statistics(ralu.site, r = xvars[[-6]]) 
 } )

 # with 1000m buffer (values around points)
 system.time( {		
  stats <- node.statistics(ralu.site, r = xvars[[-6]], buffer = 1000, 
              stats = c("min", "median", "max", "var", "skew")) 
 } ) 
 # }

Run the code above in your browser using DataLab