Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Created July 7, 2022 15:00
Show Gist options
  • Save mdsumner/abe57069a8fc1dee4dae25c70bf48d88 to your computer and use it in GitHub Desktop.
Save mdsumner/abe57069a8fc1dee4dae25c70bf48d88 to your computer and use it in GitHub Desktop.
library(terra)
#> terra 1.5.34
r <- rast("/vsicurl/https://dapds00.nci.org.au/thredds/fileServer/gb6/BRAN/BRAN2020/daily/ocean_u_2010_01.nc", lyrs = 1:10)
crs(r) <- "EPSG:4326"

e <- ext(c(xmin = 104, xmax = 138, ymin = 13, ymax = 32))

## set up a lower resolution
target_rast <- crop(rast(r), e)
res(target_rast) <- res(target_rast) * 4
system.time(project(r, target_rast, gdal = TRUE))
#>    user  system elapsed 
#>   0.653   0.144   4.678

## or just crop a template of the data 
system.time(project(r, crop(rast(r), e), gdal = TRUE))
#>    user  system elapsed 
#>   0.480   0.050   0.551

Created on 2022-07-08 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment