Calculates a convex hull on a point feature class using the Pateiro-Lopez (2009) Alphahull model

convexHull(x, alpha = 250000, sp = TRUE)

Arguments

x

SpatialPoints, SpatialPointsDataFrame, sf or matrix object representing [x,y] coordinates

alpha

Alpha parameter for adjusting boundary tension

sp

Output an sp SpatialPolygonsDataFrame object (TRUE/FALSE)

Value

SpatialPolygons object

Note

This method provides flexibility over traditional convex functions in that the the alpha parameter can be adjusted to relax or increase tension between boundary-edge points Due to licensing constraints associated with the alphahull package, this function is not available in the CRAN release. The function must be called from the package NAMESPACE using: spatialEco:::convexHull. If sp = FALSE an sf polygon class object will be returned

References

Pateiro-Lopez & Rodriguez-Casal (2009) Generalizing the Convex Hull of a Sample: The R Package alphahull. Journal of Statistical Software 34(5):1-28

Author

Jeffrey S. Evans <jeffrey_evans@tnc.org>

Examples

#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
#### points example data(meuse) coordinates(meuse) = ~x+y a <- convexHull(meuse, alpha=100000)
#> Error in convexHull(meuse, alpha = 1e+05): could not find function "convexHull"
plot(a)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'a' not found
points(meuse, pch=19)
#> Error in plot.xy(xy.coords(x, y), type = type, ...): plot.new has not been called yet
# Test multiple alpha values par(mfcol=c(2,2)) for (a in c(500, 1500, 5000, 100000)) { ch <- convexHull(meuse, alpha = a) plot(ch) points(meuse, pch=19) title( paste0("alpha=", a)) }
#> Error in convexHull(meuse, alpha = a): could not find function "convexHull"
if (FALSE) { #### Polygon example data(meuse) coordinates(meuse) = ~x+y meuse <- as(meuse, "sf") meuse_poly <- st_buffer(meuse[sample(1:nrow(meuse),10),], dist = meuse$elev*15) # Create [x,y] points representing polygon boundaries poly_points <- sf::st_segmentize(meuse_poly, dfMaxLength = 5) %>% sf::st_coordinates() %>% as.data.frame() %>% subset(select = c(X, Y)) %>% sf::st_as_sf(coords = c("X", "Y")) a <- convexHull(poly_points, alpha = 100000, sp=FALSE) plot(sf::st_geometry(a), cex=1.5, col="red") plot(sf::st_geometry(meuse_poly), col="black", add=TRUE) }