# 7.1 Landscape metrics for a single area

Some research designs may just need landscape metrics for a single area or several study areas and that is what the SDMToolsl package is able to estimate in the code that follows. While the single area can be defined by the extent of the raster we imported as in previous chapters, the ability of the SDMToolsl package to determine patch and class statistics depends on the area defined by the user from that could be study site, within polygons such as counties or townships, or within buffers around locations.

2. Set working directory to the extracted folder in R under File - Change dir...
3. First we need to load the packages needed for the exercise
library(SDMTools)
library(raster)
library(plyr)
library(maptools)
library(rgdal)

4. Now open the script "Frag_Autot.R" and run code directly from the script

#Load vegetation raster layer textfile clipped in ArcMap
crops <-raster("crop2012utm12.tif")
plot(crops)
class(crops)
as.matrix(table(values(crops)))
proj4string(crops)
crops
#reclassify the values into 9 groups # all values between 0 and 20 equal 1, #etc.
m <- c(-Inf,0,NA,2, 7, 2, 20, 60, 3, 60, 70, 4, 110, 132, 5, 133, 150, 6,
151, 191, 7, 192,Inf,NA)
rclmat <- matrix(m, ncol=3, byrow=TRUE)
rc <- reclassify(crops, rclmat)
plot(rc)
rc
as.matrix(table(values(rc)))#Look at the resulting vegetation categories
#Now we get into Landscape Metrics with the SDTM Tool
#Calculate the Patch statistics
ps.data = PatchStat(rc)
ps.data
str(ps.data)
#data.frame’: 7 obs. of 12 variables:
#\$ patchID : int 1 2 3 4 5 6 7
# \$ n.cell : int 16 7260 370104 258106 42429 1016835 726939
# \$ n.core.cell : int 0 2844 222965 107046 1241 699160 279134
# \$ n.edges.perimeter: int 50 7902 206012 261672 98766 406726 662034
# \$ n.edges.internal : int 14 21138 1274404 770752 70950 3660614 2245722
# \$ area : num 16 7260 370104 258106 42429 ...
# \$ core.area : num 0 2844 222965 107046 1241 ...
# \$ perimeter : num 50 7902 206012 261672 98766 ...
# \$ perim.area.ratio : num 3.125 1.088 0.557 1.014 2.328 ...
# \$ shape.index : num 3.12 23.11 84.64 128.65 119.86 ...
# \$ frac.dim.index : num 1.82 1.71 1.69 1.78 1.9 ...
# \$ core.area.index : num 0 0.3917 0.6024 0.4147 0.0292 ...
#Calculate the Class statistics
cl.data = ClassStat(rc)
cl.data
str(cl.data)
#’data.frame’: 7 obs. of 38 variables:
NOTE the difference in the output from function PatchStat and ClassStat.