R/extent_transforms.R

# extentFromCells <- function(x, cells) {
#   dx_r <- res(x)[1] * c(-1, 1) * 0.5
#   dy_r <- res(x)[2] * c(-1, 1) * 0.5
#   raster::extent(range(raster::xFromCell(x, cells)) + dx_r, range(raster::yFromCell(x, cells)) + dy_r)
# }


## from angstroms
set_indextent <- function (x) {
  raster::setExtent(x, raster::extent(0, ncol(x), 0, nrow(x)))
}


#' Index extent
#' 
#' Extent in index space. 
#' 
#' Convert a geographic extent into purely index space. 
#' @param x raster layer
#' @param ex extent 
#'
#' @return  extent object
#' @export
#'
index_extent <- function(x, ex) {
  raster::extentFromCells(set_indextent(x), raster::cellsFromExtent(x, ex))
}

Try the tabularaster package in your browser

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

tabularaster documentation built on May 2, 2019, 7:02 a.m.