Learn R Programming

SVG (version 1.0.0)

getSpatialNeighbors_Delaunay: Build Spatial Network via Delaunay Triangulation

Description

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
)

Value

Square numeric matrix of spatial adjacency weights.

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.

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

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

# \donttest{
if (requireNamespace("geometry", quietly = TRUE)) {
    W <- getSpatialNeighbors_Delaunay(coords)
}
# }

Run the code above in your browser using DataLab