R/sp_create_ellipse.R

Defines functions sp_create_ellipse

Documented in sp_create_ellipse

#' Function to create a elliptical polygon from a point, usually used for 
#' filtering. 
#' 
#' @param latitude Latitude of a point. 
#'
#' @param longitude Longitude of a point. 
#'
#' @param width Width of radius. \code{"width"}'s unit is in the projection of
#' \code{projection}. The default is 0.01 decimal degrees. 
#'
#' @param projection A projection string. Default is the WGS84 string. 
#' 
#' @author Stuart K. Grange
#'
#' @export
sp_create_ellipse <- function(latitude, longitude, width = 0.01,
                              projection = projection_wgs84()) {
  
  # Create a point
  sp_point <- SpatialPoints(cbind(longitude, latitude))
  
  # Give projection
  sp_point <- sp_transform(sp_point, projection, warn = FALSE)
  
  # Buffer point
  suppressWarnings(
    sp_polygon <- sp_buffer(sp_point, width = width)
  )
  
  return(sp_polygon)
  
}
skgrange/gissr documentation built on Feb. 24, 2024, 2:55 p.m.