0

I have a around 1000 raster tiles. I am trying to merge them as a single raster tile.

library(raster)
raster_tile_path <- list.files("file_path", full.names = TRUE,
                                        pattern = ".tif" ))

merge_tile  <- lapply(raster_tile_path, raster)
merge_tile  <- do.call(merge, c(merge_tile, tolerance = 1))

Upon running, i get this error:

Error in rgdal::getRasterData(con, offset = offs, region.dim = reg, band = object@data@band) : Failure during raster IO

Someone already suggested the source of error: https://stackoverflow.com/a/67607770/9101903 could be a bad or corrupted raster tile. But it seems that there is no solution to identify or ignore this specific raster tile.

Anybody got an idea on how to solve this?

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
Ankit Sagar
  • 61
  • 1
  • 8

1 Answers1

1

If there is a corrupted file, you should be able to find it like this

for (i in 1:length(merge_tile)) {
    x = merge_tile[[i]] * 1
}

When an error occurs, tile i is corrupted

You could also try

library(terra)
v <- vrt(raster_tile_path)
writeRaster(v, "file.tif")
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63