R/create_raster.R

Defines functions create_raster

Documented in create_raster

#' Create a raster at a certain resolution
#'
#' Utility function to generate a raster at a certain resolution (with rounded coordinates).
#' @param x geographical object (that supports extent).
#' @param res desired resolution (default 200).
#' @param ... passed through to \code{\link{raster}} function.
#' @return [`raster::raster`] object
#' @keywords internal
create_raster <- function(x, res = 200, ...){
  stopifnot(length(res) == 1)
  ext <- raster::extent(x)[] / res
  ext[c(1,3)] <- floor(ext[c(1,3)])
  ext[c(2,4)] <- ceiling(ext[c(2,4)])
  raster::raster( raster::extent(res*ext)
                , res = res
                , crs = raster::crs(x)
                , ...
                )
}

Try the sdcSpatial package in your browser

Any scripts or data that you put into this service are public.

sdcSpatial documentation built on March 24, 2022, 5:05 p.m.