Computes the convex hull of an sf object, returning the boundaries of the smallest polygon that can enclose all geometries in the input.
Details
The convex hull is the smallest convex polygon that encloses all points in the input sf object. This function computes the convex hull by first uniting all geometries in the input using st_union(), and then applying st_convex_hull() to obtain the polygonal boundary. The result is returned as an sf object containing the convex hull geometry.
Examples
library(sf)
# Create example sf object
points <- st_sfc(st_point(c(0,0)), st_point(c(1,1)), st_point(c(2,2)), st_point(c(0,2)))
sf_points <- st_sf(geometry = points)
# Calculate the convex hull
convex_hull_result <- create_convex_hull(sf_points)
# Plot the result
plot(sf_points, col = 'blue', pch = 19)
plot(convex_hull_result, add = TRUE, border = 'red')
