Skip to contents

Constructs spatial polygon objects from boundary points generated by the getBoundary() function. Each set of boundary points (grouped by region_id) is converted into a closed polygon. This function ensures that each polygon is valid and ready for downstream spatial analysis.

Usage

buildBoundaryPoly(boundary = NULL)

Arguments

boundary

A data frame of boundary points, typically returned by getBoundary(). Must contain columns x, y, and region_id.

Value

An sf object containing one or more valid POLYGON geometries with a region_id column.

Examples

# Load coordinates
coords <- readRDS(system.file("extdata", "MouseBrainCoords.rds",
    package = "SpNeigh"
))

# Get boundary points for cluster 2
boundary_points <- getBoundary(data = coords, one_cluster = 2)

# Convert to polygon
boundary_polys <- buildBoundaryPoly(boundary_points)

# Plot the resulting polygons
plot(boundary_polys)