Get rema in longlat for a given extent, and resolution.
2m resolution is some thing like 1/50000 of a degree, so 3e-5 gives cells with 4m^2 area at 70S
#' Get REMA v2 data in longlat
#'
#' This is crafted VRT hosted on github that references the source 2m GeoTIFFs and some pre-rendered lower resolutions,
#' so we can make data from large areas quickly as well as small areas.
#'
#' Note that AWS_NO_SIGN_REQUEST=YES must be set, i.e. 'Sys.setenv(AWS_NO_SIGN_REQUEST="YES")'
#' @param extent xmin,xmax,ymin,ymax in longlat values
#' @param res resolution in degrees (see Details)
#' @param method bilinear use bilinear resampling when changing resolution (set to 'near' for no resampling)
#' @param ... arguments passed to 'terra::project()' such as "filename"
#' @examples
#' rema_longlat(c(100, 120, -70, -60), res = .1, filename = "myrema.tif")
#' # rema_longlat(c(113.95, 114, -66.32, -66.3), res = c(3e-6, 3e-5), filename = "local.tif", threads = TRUE)
rema_longlat <- function(extent = c(-180, 180, -90, -65), res = c(1, 1), method = "bilinear", ...) {
r <- terra::rast("/vsicurl/https://raw.githubusercontent.com/mdsumner/rema-ovr/main/REMA-2m_dem_ovr.vrt")
terra::project(r, terra::rast(terra::ext(extent), res = res, crs = "EPSG:4326"), by_util = TRUE, method = method, ...)
}
## always set this for high resolution requests
Sys.setenv(AWS_NO_SIGN_REQUEST="YES")
library(terra)
plot(rema_longlat(c(100, 120, -70, -60), res = .1, filename = "myrema.tif"))
plot(rema_longlat(c(113.95, 114, -66.32, -66.3), res = c(3e-6, 3e-5), filename = "local.tif", threads = TRUE))
plot(rema_longlat(c(100, 120, -70, -60), res = .1, filename = "myrema.tif"))
plot(rema_longlat(c(113.95, 114, -66.32, -66.3), res = 3e-5, filename = "local.tif", threads = TRUE))
Created on 2024-12-11 with reprex v2.0.2
Another example, Scullens monolith