João Gonçalves 28th March 2019
SDMconnect is a R package/toolkit for performing raster-based connectivity analyses using Species Distribution Models as inputs. The package requires a resistance or permeability surface for cost-based path analyses.
The package also implements the approach proposed by Gonçalves et al., 2016 for simulating multiple routes/paths and then calculate the average cost distance between source cells and multiple target cells located in k distinct near-neighboring habitat clumps.
References: Gonçalves, J., Honrado, J.P., Vicente, J.R., Civantos, E., 2016. A model-based framework for assessing the vulnerability of low dispersal vertebrates to landscape fragmentation under environmental change. Ecological Complexity 28, 174-186. link
-
Installing development libraries: building packages from source requires the appropriate development libraries for your operating system.
-
Windows: install Rtools.
-
macOS: install Xcode commandline tools from the terminal:
xcode-select install. -
Debian/Ubuntu Linux: ensure
r-base-devis installed.
See here for more details.
-
-
Installing rJava for LORACS
SDMconnect offers the ability to perform connectivity analyses based on LORACS multiple-shortest path (MSP) approach. To enable this, a suitable Java installation must be provided to R and the rJava package. This means that R's architecture (32-bit, 64-bit or both) must match that of Java. The best way to enable this is to install the Java Development Kit 8 from the following page and then proceed to install rJava using: install.packages("rJava").
See also this info: link-1 and this one link-2
- Installing SDMconnect from GitHub:
if(!("devtools" %in% rownames(installed.packages())))
install.packages("devtools")
devtools::install_github("joaofgoncalves/SDMconnect")In this example we will apply the approach in Gonçalves et al., 2016 to evaluate the cost-based distance between areas loosing habitat suitability and stable suitable areas based on randomly simulated test data:
# Load required packages
library(SDMconnect)
library(SDMconnect)
library(rasterVis)# Make some test data
testData <- generateTestData(nrow = 50, ncol = 50)
sdm1 <- testData$rstbin1 # SDM for ti
sdm2 <- testData$rstbin2 # SDM for tj
costLayer <- testData$costLayer # A resistance layer
# Calculate the shortest path distance
kspDist <- kShortestPathDistance(sdm1, sdm2, costLayer=costLayer,
costLayerType = "resistance",
k = 5, fromCellsType = "loss",
toCellsType = "suitable", clumpDirs = 4)Let's start by plotting the simulated SDM's and their "changes":
# Simulated SDM maps
sdm1 <- ratify(sdm1)
sdm2 <- ratify(sdm2)
levels(sdm1) <- data.frame(ID=0:1,types=c('Unsuitable', 'Suitable'))
levels(sdm2) <- data.frame(ID=0:1,types=c('Unsuitable', 'Suitable'))
levelplot(stack(sdm1, sdm2),
main=c("Habitat suitability - time t_i",
"Habitat suitability - time t_j"),margin=FALSE,
col.regions=c("#E0DEB6", "#61755E"), names.attr=rep("",2))# SDM dynamics/change map classes:
# [1] no change: unsuitable (0,0)
# [2] change: gain (0,1)
# [3] change: loss (1,0)
# [4] no change: suitable (1,1)
#
changeMap <- sdmChangeMap(sdm1, sdm2)
changeMap <- ratify(changeMap)
levels(changeMap) <- data.frame(ID=1:4,types=c('Unsuitable', 'Gain', 'Loss', 'Suitable'))
levelplot(changeMap, main="Habitat suitability change map",margin=FALSE,
col.regions=c("#D1D1D1", "#7D90D1", "#BD5644", "#4B784A"))Let´s check some source-target pixels generated from the simulated sample data:
# Make the source-target matrix to plot sample points
stMat <- makeSourceTargetMatrix(rstDyn = changeMap, clumpDirs = 4, k = 5,
maxTries = 50, verbose = TRUE,
edgesPixOnly = FALSE)plotSTmatrix(stMat, changeMap, rand = 3)Now, finnally, the results for the k-shortest path distance analysis:
levelplot(stack(costLayer, kspDist$rst$AvgDist_k_5),
main=c("Resistance layer","Avg. cost distance (k=5)"),margin=FALSE,
par.settings=BuRdTheme())SDMconnect also allows to calculate the overlap of different shortest paths connecting all source->target cells:
kspOv <- kShortestPathOverlap(sdm1, sdm2, costLayer=costLayer, costLayerType = "resistance",
k = 5, fromCellsType = "loss", toCellsType = "suitable",
clumpDirs = 4)levelplot(kspOv,main="Shortest paths overlap",margin=FALSE,
par.settings=BuRdTheme())



