Generate an outer or inner boundary polygon by buffering an existing boundary
Source:R/GetBoundary.R
GetOuterBoundary.RdComputes an expanded or shrunken boundary by applying a spatial buffer
to an existing polygon.
The input can be either boundary points (as returned by getBoundary())
or polygon geometries (as returned by buildBoundaryPoly()).
This is useful for defining outer spatial neighborhoods or for
shrinking boundaries inward to define inner regions.
Value
An sf object of expanded outer boundary polygons with the
same region_id values as the original input.
Details
Be careful: when using a negative buffer distance (for inner boundaries), polygons may collapse, become invalid, or disappear entirely if the buffer width exceeds the shape's interior size.
See also
getInnerBoundary() for a simplified wrapper for inward shrinking.
Examples
# Load coordinates
coords <- readRDS(system.file("extdata", "MouseBrainCoords.rds",
package = "SpNeigh"
))
# Get boundary points of cluster 2
boundary_points <- getBoundary(data = coords, one_cluster = 2)
# Build polygons from boundary points
boundary_polys <- buildBoundaryPoly(boundary_points)
# Generate outer boundaries with 100-unit buffer
outer1 <- getOuterBoundary(boundary_points, dist = 100)
outer2 <- getOuterBoundary(boundary_polys, dist = 100)
# Plot original and expanded boundaries
plot(boundary_polys)
plot(outer2, add = TRUE, border = "red")