Skip to content

Instantly share code, notes, and snippets.

View florianm's full-sized avatar
🐢

Florian Mayer florianm

🐢
View GitHub Profile
terra_out <- 
  function(x) {
    loadNamespace("terra")
    if (isS4(x) && inherits(x, "SpatRaster")) {
      x <- try(list(extent = c(terra::xmin(x), terra::xmax(x), terra::ymin(x), terra::ymax(x)),
                    dimension = dim(x)[2:1],
                    projection = terra::crs(x), 
                    lonlat = terra::is.lonlat(x), terra = TRUE), silent = TRUE)
      if (inherits(x, "try-error")) stop("cannot use terra grid")