R/polygonArea.R

Defines functions polygonArea

Documented in polygonArea

#' polygonArea function
#'
#' function to (do something)
#'
#' @param coords [value]
#' @return [value]
#' @details [fill in details here]
#' @examples # none
#' @export
polygonArea <- function(coords){
	if(!"matrix" %in% class(coords) | ncol(coords) != 2) stop("please provide a two column matrix of coordinates, x & y")
	coords <- unique(coords)
	x <- coords[,1]
	y <- coords[,2]

	area <- NULL
	j <- length(x) 

	for(i in 1:length(x)){
		area[i] <- (x[j]*y[i]) - (x[i]*y[j])
		j <- i
	}
	abs(sum(area) / 2)
}
nsantantonio/fieldMapR documentation built on Feb. 4, 2025, 3:07 a.m.