Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

proximity_matrix

Proximity matrix


Description

Create a matrix showing which planning units are within a certain spatial proximity to each other.

Usage

proximity_matrix(x, distance)

## S3 method for class 'Raster'
proximity_matrix(x, distance)

## S3 method for class 'SpatialPolygons'
proximity_matrix(x, distance)

## S3 method for class 'SpatialLines'
proximity_matrix(x, distance)

## S3 method for class 'SpatialPoints'
proximity_matrix(x, distance)

## S3 method for class 'sf'
proximity_matrix(x, distance)

## Default S3 method:
proximity_matrix(x, distance)

Arguments

x

Raster, Spatial, or sf::sf() object representing planning units.

distance

numeric distance threshold. Planning units that are further apart from each other than this threshold are not treated as being within proximity of each other.

Details

Proximity calculations are performed using sf::st_is_within_distance().

Value

dsCMatrix symmetric sparse matrix object. Each row and column represents a planning unit. Cells values indicate if the pair-wise distances between different planning units are within the distance threshold or not (using ones and zeros). To reduce computational burden, cells among the matrix diagonal are set to zero. Furthermore, if the argument to x is a Raster object, then cells with NA values are set to zero too.

Examples

# load data
data(sim_pu_raster, sim_pu_sf, sim_pu_lines, sim_pu_points)

# create proximity matrix using raster data
## crop raster to 9 cells to provide a small example
r <- crop(sim_pu_raster, c(0, 0.3, 0, 0.3))

## make proximity matrix using a distance threshold of 2
cm_raster <- proximity_matrix(r, distance = 2)

# create proximity matrix using polygon (sf) data
## subset 9 polygons to provide a small example
ply <- sim_pu_sf[c(1:2, 10:12, 20:22), ]

## make proximity matrix using a distance threshold of 2
cm_ply <- proximity_matrix(ply, distance = 2)

# create proximity matrix using line (Spatial) data
## subset 9 lines to provide a small example
lns <- sim_pu_lines[c(1:2, 10:12, 20:22), ]

## make proximity matrix
cm_lns <- proximity_matrix(lns, distance = 2)

## create proximity matrix using point (Spatial) data
## subset 9 points to provide a small example
pts <- sim_pu_points[c(1:2, 10:12, 20:22), ]

# make proximity matrix
cm_pts <- proximity_matrix(pts, distance = 2)

# plot data and the proximity matrices
## Not run: 
par(mfrow = c(4,2))

## plot raster and proximity matrix
plot(r, main = "raster", axes = FALSE, box = FALSE)
plot(raster(as.matrix(cm_raster)), main = "proximity matrix", axes = FALSE,
     box = FALSE)

## plot polygons and proximity matrix
plot(r, main = "polygons (sf)", axes = FALSE, box = FALSE)
plot(raster(as.matrix(cm_ply)), main = "proximity matrix", axes = FALSE,
    box = FALSE)

## plot lines and proximity matrix
plot(r, main = "lines (Spatial)", axes = FALSE, box = FALSE)
plot(raster(as.matrix(cm_lns)), main = "proximity matrix", axes = FALSE,
     box = FALSE)

## plot points and proximity matrix
plot(r, main = "points (Spatial)", axes = FALSE, box = FALSE)
plot(raster(as.matrix(cm_pts)), main = "proximity matrix", axes = FALSE,
     box = FALSE)

## End(Not run)

prioritizr

Systematic Conservation Prioritization in R

v7.0.1
GPL-3
Authors
Jeffrey O Hanson [aut] (<https://orcid.org/0000-0002-4716-6134>), Richard Schuster [aut, cre] (<https://orcid.org/0000-0003-3191-7869>), Nina Morrell [aut], Matthew Strimas-Mackey [aut] (<https://orcid.org/0000-0001-8929-7776>), Matthew E Watts [aut], Peter Arcese [aut] (<https://orcid.org/0000-0002-8097-482X>), Joseph Bennett [aut] (<https://orcid.org/0000-0002-3901-9513>), Hugh P Possingham [aut] (<https://orcid.org/0000-0001-7755-996X>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.