-1

I am using R to create a Canopy height model (CHM) using DSM and DTM TIF files. I have performed this exercise previously on a smaller dataset and everything worked fine. However, I am now receiving and error that the TIFFReadDirectory:Failed (see below for the portion of code and error message).

There are approx 5,500 single band rasters in each folder.

setwd("ThisIsMyFilePath")

library(raster)
library(rgdal)
library(data.table)
library(parallel)

dtmFile <- list.files("./DTM/All/TIFs")
dsmFile <- list.files("./DSM/All/TIFs")

rastTab <- data.table(dtmFile, dsmFile)
rastTab[,dtmRast:=lapply(file.path("./DTM/All/TIFs", dtmFile), raster),]
rastTab[,dsmRast:=lapply(file.path("./DSM/All/TIFs", dsmFile), raster),]


Error in .local(.Object, ...) : 
  ThisIsMyFilePath\All\TIFs\TR23ne_DTM_2m.tif: TIFFReadDirectory:Failed to read directory at offset 9858754

In addition: There were 50 or more warnings (use warnings() to see the first 50)
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file.```
2
  • What happens when you try and read just that one TIFF given in the error message? Maybe its corrupted. You should try that.
    – Spacedman
    Sep 11 at 13:37
  • @Spacedman Thanks for your reply :) All sorted! You were totally right. I removed the TIF as it was corrupted. After re-running the script a few others popped up but it is running fine now. Thanks again.
    – GISLad
    Sep 16 at 15:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.