You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have several tiles and I need to merge them; but using terra's merge function will result in a ridiculously huge output file while using raster's merge function behaves very well and the output makes sense. In my real case, the output should be around 7GB but when I use terra's merge function, it results in an output file of ~120GB!!!
I managed to provide a reproducible example here. In this example, I have 80 tiles of ~6.5MB (in total ~520MB). Using terra, the merged file is ~4GB (!!!) while using raster results in a merged file of ~850MB (which is what expected).
Interestingly, if I just rewrite the result from terra, it will be ~850MB which totally would makes sense.
library(terra)
# terra 1.7.55
# creating 80 tiles of 1x1 out of 121 tiles for the region
n <- 80
allComb <- expand.grid(lon = seq(-100, -90, by = 1), lat = seq(40, 50, by = 1))
allComb <- allComb[sample.int(nrow(allComb), n),]
for (i in 1:n) {
writeRaster(rast(xmin=allComb[i, "lon"], xmax=allComb[i, "lon"]+1,
ymin=allComb[i, "lat"], ymax=allComb[i, "lat"]+1, res=0.0001, vals=i),
paste0("part_", i, ".tif"), overwrite = TRUE)
}
# merge tiles using terra
allParts <- list.files(pattern = "^part_.+\\.tif", full.names = TRUE)
all_terra <- merge(sprc(allParts), first = TRUE, na.rm = TRUE,
filename = "all_terra.tif", overwrite = TRUE)
# merge tiles using raster
allParts <- list.files(pattern = "^part_.+\\.tif", full.names = TRUE)
allParts <- lapply(allParts, raster::raster)
allParts$filename <- "all_raster.tif"
all_raster <- do.call(raster::merge, allParts)
# rewrite the terra output
writeRaster(all_terra, filename = "all_terra_rewrite.tif", overwrite = TRUE)
The text was updated successfully, but these errors were encountered:
I have added two alternative methods ("algo=2" and "algo=3") that give much better compression, but in my tests, that comes at the expense of speed.
If the merged raster is not a final output, another option is to use "algo=3" with no output filename. That returns a virtually merged raster (no new file) that can be used in subsequent computation.
Hi,
I have several tiles and I need to merge them; but using terra's
merge
function will result in a ridiculously huge output file while using raster'smerge
function behaves very well and the output makes sense. In my real case, the output should be around 7GB but when I use terra'smerge
function, it results in an output file of ~120GB!!!I managed to provide a reproducible example here. In this example, I have 80 tiles of ~6.5MB (in total ~520MB). Using terra, the merged file is ~4GB (!!!) while using raster results in a merged file of ~850MB (which is what expected).
Interestingly, if I just rewrite the result from terra, it will be ~850MB which totally would makes sense.
The text was updated successfully, but these errors were encountered: