convexHull: Alpha Convex Hull

View source: R/convexHull.R

convexHullR Documentation

Alpha Convex Hull

Description

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

Usage

convexHull(x, alpha = 250000)

Arguments

x

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

alpha

Alpha parameter for adjusting boundary tension

Value

sf POLYGIN 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.

Author(s)

Jeffrey S. Evans <jeffrey_evans@tnc.org>

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

Examples

 library(sf)
 
 #### points example
if(require(sp, quietly = TRUE)) {
  data(meuse, package = "sp")
  meuse <- st_as_sf(meuse, coords = c("x", "y"), crs = 28992, 
                    agr = "constant")
}
  
  a <- convexHull(meuse, alpha=100000)
    plot(a)
      plot(st_geometry(meuse), pch=19, add=TRUE)

  # Test multiple alpha values
   par(mfcol=c(2,2))
     for (a in c(500, 1500, 5000, 100000)) {
     ch <- convexHull(meuse, alpha = a)
       plot(ch, key.pos = NULL, reset = FALSE)
        plot(st_geometry(meuse), pch=19, add=TRUE)
          title( paste0("alpha=", a))		 
     }

 ## Not run: 
  #### Polygon example (note, I draw a sample to make more tractable)
  data(meuse, package = "sp")
    meuse <- st_as_sf(meuse, coords = c("x", "y"), 
                      crs = 28992, agr = "constant")
       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")) 

  # Draw random sample to make tractable
  poly_points <- poly_points[sample(1:nrow(poly_points), 500),]

  # calculate convex hull		  
  a <- convexHull(poly_points, alpha = 10000)
    plot(sf::st_geometry(a), cex=1.5, col="red") 
      plot(sf::st_geometry(poly_points), col="black", add=TRUE)

## End(Not run)


jeffreyevans/spatialEco documentation built on April 4, 2024, 10:53 a.m.