I am trying to project a large raster to UTM (meters), but I keep crashing my laptop (16GB) due to a memory shortage. It seems like using projectRaster tends to deplete the machine's memory, and some solutions have been suggested in questions like this one. However, even using the suggested solution my laptop keeps crashing. The raster in question is a mosaic that I create from 4 DEM tiles downloaded from USGS with a resolution of 1/3 arc second (~10m) that correspond to the city of Milwaukee, WI. This mosaic is 396.8 Mb. The process goes as follows and can be run in any machine to download the rasters:
library(raster) rasterOptions(memfrac = 0.3) # the solution suggested in several questions to limit access to memory by the raster package. import the four rasters via their individual link. r1 <- raster("https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/1/TIFF/n43w089/USGS_1_n43w089.tif") r2 <- raster("https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/1/TIFF/n44w088/USGS_1_n44w088.tif") r3 <- raster("https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/1/TIFF/n43w088/USGS_1_n43w088.tif") r4 <- raster("https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/1/TIFF/n44w089/USGS_1_n44w089.tif") # create a list with the four rasters and merge them into one single raster layer rl <- list(r1, r2, r3 , r4) mosaic <- do.call(merge, rl) rm(r1,r2,r3,r4, rl) # remove unnecessary files in memory to save space # project the mosaic layer to UTM zone 16N (m) -- THIS IS WHERE THE COMPUTER CRASHES mosaic <- projectRaster(mosaic, crs = "+proj=utm +zone=16 +ellps=GRS80 +datum=NAD83 +units=m +no_defs")
In this other question, rasterOptions is used to set
chunksize = 1e+04 and
maxmemory to 1e+0.6. I tried doing this and my machine didnt complete the line
mosaic <- do.call(merge, rl) in the entire night.
I have considered the option of projecting each raster (r1, r2, r3, r4) separately before creaing the mosaic, but I am weary of the issues that this may cause at the time of merging them together, and I would very much rather find a memory efficient way to handle the reprojection than just avoiding it with a by-pass.