Reference and Disclaimer: For this exercise, I have used explanation and codes from the book Spatial Ecology and Conservation Modeling by Robert Fletcher & Marie-Josée Fortin. For analysis, I have used codes from (Landscape Genetic Data Analysis with R)[https://bookdown.org/hhwagner1/LandGenCourse_book/] and (How To Do Archaeological Science Using R)[https://benmarwick.github.io/How-To-Do-Archaeological-Science-Using-R/index.html]
I have got help from Carleisha Hanns and Tyler Putt in completing this assignment.
Load the necessary packages
rm(list = ls())
## First specify the packages of interest
= c("raster", "rgeos","rgdal","gdistance","igraph","fitdistrplus","fdrtool","ggplot2")
packages
## Now load or install&load all
<- lapply(
package.check
packages,FUN = function(x) {
if (!require(x, character.only = TRUE)) {
install.packages(x, dependencies = TRUE)
library(x, character.only = TRUE)
}
}
)par(mfrow = c(1, 1))
setwd("D:/UGA/Academic Course Work/Fall-2022/FANR-8400-AdvGIS/Assignments/Ex5")
<- "D:/UGA/Academic Course Work/Fall-2022/FANR-8400-AdvGIS/Assignments/Ex5/BoulderElk.gdb"
fgdb ogrListLayers(fgdb)
Load the vector data and evaluate their centroid
<- readOGR(fgdb,layer="elk_areas")
area_loc projection(area_loc)
#get the centroids of plots
<- gCentroid(area_loc, byid=T)
area_loc_centroids #area_loc_centroids@coords
Note: In order to calculate costs, all of the rasters need to have exactly the same resolution, dimensions, and co-ordinate locations (i.e., the cells need to match up perfectly. The method of resampling (bilinear vs nearest-neighbor) depends on the type of data. Nearest-neighbor is for categorical data whereas bilinear interpolation is for continuous data.
<- raster("dem_30")
dem <- raster("./Cost_rasters/RoadCost.tif")
road <- raster("./Cost_rasters/streamcost.tif")
stream <- raster("./Cost_rasters/trailcost.tif")
trail
#create slope from elevation
<- terrain(dem, opt=c("slope"))
slope #make a multilayered file for extraction
<- stack(dem, slope, road, stream, trail) #merge the slope and aspect layers into a single raster object that holds all raster layers
layers names(layers) <- c("elev", "slope","road","stream","trail")
projection(layers)
rm(list=c("dem","road","stream","trail","slope"))
plot(layers)
Plot the summer and winter sites - Base raster I took slope here
#plot
plot(layers$slope)
plot(area_loc,add=T)
points(area_loc_centroids, col="grey30", pch=20)
$elev <- (1/layers$elev)
layers
<- sum(layers[[1:5]])
tot_cost
<- transition(tot_cost,
tr.cost transitionFunction = function(x) 1/mean(x), directions=8)
#Correct for geometric distortion
<- gdistance::geoCorrection(tr.cost,type = "c",multpl=FALSE)
tr.cost1
#get lcp
<- shortestPath(tr.cost1, area_loc_centroids@coords[1,], area_loc_centroids@coords[2,], output="SpatialLines") sumr_wntr_lcp
plot(raster::raster(tr.cost1))
lines(sumr_wntr_lcp, col="red", lwd=2)
points(area_loc_centroids, col="black", pch=20)
#Cost calculated in Arcpro and the final layer uploaded for further analysis in R
rm(list=c("tot_cost","tr.cost","tr.cost1","sumr_wntr_lcp"))
<- raster("./Cost_rasters/Surfacecost.tif")
surface
plot(surface)
plot(area_loc,add=T)
points(area_loc_centroids, col="grey30", pch=20)
#create a conductance transition layer: inverse of resistance data
<- transition(surface,
land_cond transitionFunction = function(x) 1/mean(x), 8)
#make correction; type=c for lcps; type = r for circuit (identical results for this example, so just use c)
<- geoCorrection(land_cond, type="c", multpl=F)
land_cond
#get lcp
<- shortestPath(land_cond, area_loc_centroids@coords[1,], area_loc_centroids@coords[2,], output="SpatialLines") sumr_wntr_lcp
#plotting this to see on the overall land data (for clarity purpose)
::plot(raster::raster(land_cond),main="Conductance")
rasterplot(area_loc,add=T)
points(area_loc_centroids, col="grey30", pch=20)
lines(sumr_wntr_lcp)
#get cumulative costs from each PA
<- accCost(land_cond, area_loc_centroids@coords[1,])
sumr.cost <- accCost(land_cond, area_loc_centroids@coords[2,])
wntr.cost
#get least-cost corridor
<- overlay(sumr.cost, wntr.cost, fun=function(x, y){return(x + y)}) leastcost_corridor
#get lower quantile
<- quantile(leastcost_corridor, probs=0.10, na.rm=TRUE)
quantile10
#make new truncated layer
<- leastcost_corridor
leastcost_corridor10 values(leastcost_corridor10) <- NA
< quantile10] <- 1 #truncate to identify corridor
leastcost_corridor10[leastcost_corridor
#plot
par(mfrow=c(1,1))
plot(leastcost_corridor)
plot(area_loc, add=T)
plot(leastcost_corridor10, legend=F,axes=F, add=T, col="purple")
points(area_loc_centroids, col="grey30")
lines(sumr_wntr_lcp, col="red", lw=3)
par(mfrow=c(2,2))
plot(sumr.cost, legend=F, main="Summer Pref loc")
plot(wntr.cost, axes=F, main="Winter Pref loc")
plot(leastcost_corridor, legend=F, main="LC path")
plot(area_loc, add=T)
points(area_loc_centroids, col="grey30", pch=20)
lines(sumr_wntr_lcp, col="red", lw=3)
plot(leastcost_corridor, axes=F, main = "LC Corridor")
plot(area_loc, add=T)
plot(leastcost_corridor10, legend=F, add=T, col="purple")
points(area_loc_centroids, col="grey30")
lines(sumr_wntr_lcp, col="red", lw=3)
par(mfrow=c(1,1))
Construct Weights - I am assigning arbitrary weights to classes of each raster variable. These weights should be based on educated guesses, empirical evidence, or to test a theory. The weights and splits should be based on regional literature. Known site locations obviously influence this understanding.
### Slope weighting Models###
<- c(0, 0.2, 0.4, 0.6, 0.8)
slp_from <- c(0.2, 0.4, 0.6, 0.8, 10)
slp_to <- c(50, 30, 15, 5, 0)
slp_wght <- cbind(slp_from, slp_to, slp_wght)
slp_rclsprint(slp_rcls)
### Elevation weighting Models###
<- c(1500, 2000, 2500, 3000, 3500)
elev_from <- c(2000, 2500, 3000, 3500,4100)
elev_to <- c(50, 30, 15, 5, 0)
elev_wght <- cbind(elev_from, elev_to, elev_wght)
elev_rclsprint(elev_rcls)
Note: In order to calculate costs, all of the rasters need to have exactly the same resolution, dimensions, and co-ordinate locations (i.e., the cells need to match up perfectly. The method of resampling (bilinear vs nearest-neighbor) depends on the type of data. Nearest-neighbor is for categorical data whereas bilinear interpolation is for continuous data.
layers"slope"]] <- reclassify(layers[["slope"]], slp_rcls)
layers[["elev"]] <- reclassify(layers[["elev"]], elev_rcls)
layers[[# plot(layers2)
<- sum(layers[[1:5]])
model_sum # plot(model_sum)
<- coordinates(model_sum)
coords <- data.frame(x = coords[,"x"], y = coords[,"y"], value = as.vector(model_sum))
x ggplot(x, aes(x = x, y = y, fill = value)) +
geom_raster(hjust = 0, vjust = 0) +
theme_minimal() +
::scale_fill_viridis() +
viridislabs(title = "Summed Sensitivity Weights")
Note: We can redo the entire analysis with this new layer
To be able to use the data in circuitscape, the polygon data is converted to rasters. Then surface cost raster and elk location rasters were both converted into .asc format. the data is then put in circuitscape.
From Circuitscape