R/sp_move.R

Defines functions sp_move

Documented in sp_move

#' Function to move/shift a spatial object. 
#' 
#' @author Stuart K. Grange
#' 
#' @param sp Spatial object. 
#' 
#' @param x Offset amount (in \code{sp} projection's units) in left-right 
#' dimension.
#' 
#' @param y Offset amount (in \code{sp} projection's units) in up-down 
#' dimension.
#' 
#' @seealso \code{\link{elide}}
#' 
#' @return Spatial object.  
#' 
#' @export
sp_move <- function(sp, x, y) {
  
  # Get projection string
  projection <- sp_projection(sp)
  
  # Do
  sp <- sp::elide(sp, shift = c(x, y))   
  
  # Add projection again
  sp <- sp_transform(sp, to = projection, warn = FALSE)
  
  return(sp)
  
}


# Wrap the function
#' @rdname sp_move
#' @export
sp_shift <- sp_move
skgrange/gissr documentation built on June 20, 2024, 12:02 a.m.