25 Aug

How to convert hdf files in tif?

Hi crazyGISfans,

Hdf format may be sometimes difficult to manage. We prefer working with geotif.
How do you do convert hdf in tif in R with gdal_translate?

library(gdalUtils)
library(tools)
 
setwd("/guru-blard/")
 
files<-list.files(, pattern=".hdf$")
band<-1
 
for (file in files){
  gdal_translate(src_dataset=get_subdatasets(file)[band], dst_dataset=paste0(file_path_sans_ext(file),"_B", band,'.tif'))
}

That’s it.

Leave a Reply

Your email address will not be published. Required fields are marked *