Skip to content

Commit

Permalink
Support Spatial* objects in update_extent()
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardlavender committed Aug 28, 2023
1 parent 0b965aa commit 3fdf088
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions R/spatial_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @title Shrink or expand an \code{\link[raster]{extent}} object
#' @description This function updates a \code{\link[raster]{raster}}'s \code{\link[raster]{extent}} by shrinking or expanding the x and y limits.
#'
#' @param x A \code{\link[raster]{raster}} or an \code{\link[raster]{extent}} object.
#' @param x An \code{\link[raster]{extent}} object or an object from which there is an \code{\link[raster]{extent}} method (e.g., a \code{\link[raster]{raster}}).
#' @param x_shift A number that defines the change in the x limits. Positive numbers increase the extent (i.e., the lower limit is reduced and the upper limit is increased) while negative numbers reduce extent (i.e., the lower limit is increased and the upper limit is decreased).
#' @param y_shift A number that defines the change in the y limits. By default, this equals \code{x_shift} (i.e., the \code{\link[raster]{extent}} is changed uniformly in all directions).
#'
Expand All @@ -30,7 +30,9 @@
#'

update_extent <- function(x, x_shift, y_shift = x_shift) {
if (inherits(x, "RasterLayer")) x <- raster::extent(x)
if (!inherits(x, "Extent")) {
x <- raster::extent(x)
}
x[1] <- x[1] - x_shift
x[2] <- x[2] + x_shift
x[3] <- x[3] - y_shift
Expand Down
2 changes: 1 addition & 1 deletion man/update_extent.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3fdf088

Please sign in to comment.