connected_matrix: Connected matrix

Description Usage Arguments Details Value Examples

Description

Create a matrix showing which planning units are spatially connected.

Usage

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

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.

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.

Value

dsCMatrix-class object.

Examples

 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")

prioritizr/prioritizrutils documentation built on May 25, 2019, 12:20 p.m.