R/mcp.R

Defines functions mcp

Documented in mcp

#' Calculate Minimum Convex Polygon (MCP) of points observations.
#'
#' @param x An sf points object.
#' @param percentile The percentile of points (distance from centroid) excluded
#' before calculating the MCP.
#'
#' @return A sf polygon object representing the MCP.
#' @export

mcp <- function(x, percentile=95){

  centroid <- sf::st_centroid(sf::st_union(x))
  dist <- as.numeric(sf::st_distance(x, centroid))
  within_percentile_range <- dist <= quantile(dist, percentile/100)
  x_filter <- st_union(x[within_percentile_range,])
  st_convex_hull(x_filter)

}
juoe/sdmflow documentation built on Feb. 23, 2020, 7:38 p.m.