GeNetIt (version 0.1-4)

graph.statistics: Point sample and statistics for edges (lines)

Description

Samples rasters for each edge and calculates specified statistics

Usage

graph.statistics(x, r, stats = c("min", "mean", "max"), buffer = NULL)

Value

data.frame object of statistics

Arguments

x

sp SpatialLinesDataFrame or sf LINE object

r

A rasterLayer, rasterStack or rasterBrick object

stats

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

buffer

Buffer distance, radius in projection units. For statistics based on edge buffer distance

Examples

Run this code
# \donttest{
 library(sp)
 library(spdep)
 library(raster)
   data(rasters)
   data(ralu.site)
 
 xvars <- stack(rasters)
 
  dist.graph <- knn.graph(ralu.site, row.names = ralu.site$SiteName, 
                          max.dist = 1500)
   str(dist.graph@data)
   
 skew <- function(x, na.rm = TRUE) {  
           if (na.rm) x <- x[!is.na(x)]
           sum( (x - mean(x)) ^ 3) / ( length(x) * sd(x) ^ 3 )  
 		}

# Moments on continuous raster data
 system.time( {		
  stats <- graph.statistics(dist.graph, r = xvars[[-6]],  
              stats = c("min", "median", "max", "var", "skew")) 
 } ) 

# Proportional function on nominal raster data		
p <- function(x) { length(x[x < 52]) / length(x) }	
	
  system.time( {		
   nstats <- graph.statistics(dist.graph, r = xvars[[6]],
               stats = "p") 
  } ) 	

# Based on 500m buffer distance around line(s)
 system.time( {		
  stats <- graph.statistics(dist.graph, r = xvars[[-6]],  
              stats = c("min", "median", "max", "var", "skew"),
			  buffer = 500) 
 } )

 dist.graph@data <- data.frame(dist.graph@data, stats, nstats)
   str(dist.graph@data)
# }

Run the code above in your browser using DataCamp Workspace