Skip to contents

Constructs a spatial adjacency matrix using Delaunay triangulation. Two points are considered neighbors if they share an edge in the triangulation.

Usage

getSpatialNeighbors_Delaunay(
  coords,
  filter_dist = NA,
  binary = TRUE,
  verbose = FALSE
)

Arguments

coords

Numeric matrix of spatial coordinates. Rows are spatial locations, columns are x, y (and optionally z) coordinates.

filter_dist

Numeric or NA. Maximum distance threshold for neighbors. Default is NA (no filtering).

binary

Logical. If TRUE (default), return binary adjacency matrix.

verbose

Logical. Whether to print progress messages. Default is FALSE.

Value

Square numeric matrix of spatial adjacency weights.

Details

The function uses Delaunay triangulation from the geometry package. For 2D coordinates, this creates triangles. For 3D, it creates tetrahedra.

Duplicate coordinates are slightly jittered to avoid computational issues.

Examples

set.seed(42)
coords <- cbind(x = runif(50), y = runif(50))
rownames(coords) <- paste0("spot_", 1:50)
W <- getSpatialNeighbors_Delaunay(coords)