Create a matrix showing which planning units are spatially connected to each other.
connected_matrix(x, ...) # S3 method for Raster connected_matrix(x, directions = 4L, ...) # S3 method for SpatialPolygons connected_matrix(x, ...) # S3 method for SpatialLines connected_matrix(x, ...) # S3 method for SpatialPoints connected_matrix(x, distance, ...) # S3 method for default connected_matrix(x, ...)
x 


...  not used. 
directions 

distance 

dsCMatrixclass
object.
This function returns a dgCMatrixclass
sparse
matrix. Cells along the offdiagonal indicate if two planning units are
connected. Cells along the diagonal are zero to reduce memory consumption.
Note that for Rasterclass
arguments to x
,
pixels with NA
have zeros in the returned object to reduce
memory consumption and be consistent with boundary_matrix
,
and connectivity_matrix
.
# load data data(sim_pu_raster, sim_pu_polygons, sim_pu_lines, sim_pu_points) # create connected matrix using raster data ## crop raster to 9 cells r < crop(sim_pu_raster, c(0, 0.3, 0, 0.3)) ## make connected matrix cm_raster < connected_matrix(r) # create connected matrix using polygon data ## subset 9 polygons ply < sim_pu_polygons[c(1:2, 10:12, 20:22), ] ## make connected matrix cm_ply < connected_matrix(ply) # create connected matrix using polygon line ## subset 9 lines lns < sim_pu_lines[c(1:2, 10:12, 20:22), ] ## make connected matrix cm_lns < connected_matrix(lns) ## create connected matrix using point data ## subset 9 points pts < sim_pu_points[c(1:2, 10:12, 20:22), ] # make connected matrix cm_pts < connected_matrix(pts, distance = 0.1) # plot data and the connected matricespar(mfrow = c(4,2)) ## plot raster and connected matrix plot(r, main = "raster", axes = FALSE, box = FALSE) plot(raster(as.matrix(cm_raster)), main = "connected matrix", axes = FALSE, box = FALSE) ## plot polygons and connected matrix plot(r, main = "polygons", axes = FALSE, box = FALSE) plot(raster(as.matrix(cm_ply)), main = "connected matrix", axes = FALSE, box = FALSE) ## plot lines and connected matrix plot(r, main = "lines", axes = FALSE, box = FALSE) plot(raster(as.matrix(cm_lns)), main = "connected matrix", axes = FALSE, box = FALSE) ## plot points and connected matrix plot(r, main = "points", axes = FALSE, box = FALSE) plot(raster(as.matrix(cm_pts)), main = "connected matrix", axes = FALSE, box = FALSE)