Description Usage Arguments Details Value Examples
Create a matrix showing which planning units are spatially connected.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | connected_matrix(x, ...)
## S3 method for class 'Raster'
connected_matrix(x, directions = 4L, ...)
## S3 method for class 'SpatialPolygons'
connected_matrix(x, ...)
## S3 method for class 'SpatialLines'
connected_matrix(x, ...)
## S3 method for class 'SpatialPoints'
connected_matrix(x, distance, ...)
## S3 method for class 'data.frame'
connected_matrix(x, ...)
|
x |
|
... |
not used. |
directions |
|
distance |
|
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.
dsCMatrix-class
object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | ## 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")
plot(raster(as.matrix(cm_raster)), main = "connected matrix")
# plot polygons and connected matrix
plot(r, main = "polygons")
plot(raster(as.matrix(cm_ply)), main = "connected matrix")
# plot lines and connected matrix
plot(r, main = "lines")
plot(raster(as.matrix(cm_lns)), main = "connected matrix")
# plot points and connected matrix
plot(r, main = "points")
plot(raster(as.matrix(cm_pts)), main = "connected matrix")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.