R/convex_richness.R

Defines functions convex_richness

Documented in convex_richness

#' Convex Richness
#'
#' It creates a convex hull around observation records and sets the area inside as '1' (species is present)#' It will then find the nearest non-NA cell and extend the raster so that no observation records sit on NA pixels.
#' It sets all areas outside of the convex hull as '0' (species absent).
#' The resulting raster images can be subsequently stacked and summed.
#'
#' @param xy xy coordinates specifying cell centroids. Ensure that column headings are lower case and labelled as longitude/latitude or lat/long or xy.
#' @param raster Raster which will be extended
#' @param output.table Logical. If output.table=TRUE then a data.frame will be displayed instead of a raster. If output.table=FALSE then an extended raster will be displayed. Default is output.table=FALSE
#' @param fact Integer. This argument disaggregates raster* (i.e. increases the reshighres.split<-split.raster(raster=global_climate[[1]], ppside = 10, save = TRUE, plot=FALSE, raster.name="highres_split_")
#' @param only.na Logical. If TRUE, the function will only calculate new values for NA cells. When TRUE, processing time is greatly reduced.
#' @keywords None.
#' @export
#' @examples Coming soon.

convex_richness<-function(raster,observation.points){

  ch <- convHull(observation.points)
  p <- polygons(ch)
  zz<-mask(raster,p)
  inverse<-mask(raster, p, inverse=F, updatevalue=0)
  inverse[zz]<-1
  return(inverse)

}
simon-tarr/island documentation built on May 6, 2019, 8:05 p.m.