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, ...)

Arguments

x

Raster-class or Spatial-class object. Note that if x is a Raster-class object then it must have only one layer.

...

not used.

directions

integer If x is a Raster-class object, the number of directions in which cells should be connected: 4 (rook's case), 8 (queen's case), 16 (knight and one-cell queen moves), or "bishop" to connect cells with one-cell diagonal moves.

distance

numeric If x is a SpatialPoints-class object, the distance that planning units have to be within in order to qualify as being connected.

Value

dsCMatrix-class object.

Details

This function returns a dgCMatrix-class sparse matrix. Cells along the off-diagonal indicate if two planning units are connected. Cells along the diagonal are zero to reduce memory consumption. Note that for Raster-class 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.

Examples

# 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 matrices par(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)