Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to transform HDF5 to geotiff using gdal_translate or gdalwarp?

Tags:

hdf5

gdal

geotiff

I have a 10° by 10° ungeoreferenced HDF5 that I want to convert to geotiff. I have tried 2 approaches (1) gdalwarp and (2) gdal_translate but was not able to find how to convert the files.

1) gdalwarp

gdalwarp -t_srs '+proj=longlat +datum=WGS84 +no_defs ' -te 40 30 50 40 -tr 0.0089285714 -0.0089285714 -multi HDF5:"/PathToTheHDF/FileName.HDF5"://SUBDATASET /PathToOutput/FileName_Subdataset.tif

I have the following error:

ERROR 1: Unable to compute a transformation between pixel/line
and georeferenced coordinates for ...
There is no affine transformation and no GCPs.
256

2) gdal_translate

gdal_translate -of GTiff -a_srs '+proj=longlat +datum=WGS84 +no_defs ' -a_ullr 40 40 50 30 HDF5:"/PathToTheHDF/FileName.HDF5"://SUBDATASET /PathToOutput/FileName_Subdataset.tif

and I have the following error:

Input file size is 1120, 1120
0HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 140288255100800:
  #000: ../../../src/H5Dio.c line 182 in H5Dread(): can't read data
    major: Dataset
    minor: Read failed
  #001: ../../../src/H5Dio.c line 550 in H5D__read(): can't read data
    major: Dataset
    minor: Read failed
  #002: ../../../src/H5Dchunk.c line 1837 in H5D__chunk_read(): unable to read raw data chunk
    major: Low-level I/O
    minor: Read failed
  #003: ../../../src/H5Dchunk.c line 2868 in H5D__chunk_lock(): data pipeline read failed
    major: Data filters
    minor: Filter operation failed
  #004: ../../../src/H5Z.c line 1150 in H5Z_pipeline(): required filter 'szip' is not registered
    major: Data filters
    minor: Read failed
  #005: ../../../src/H5PL.c line 293 in H5PL_load(): search in paths failed
    major: Plugin for dynamically loaded library
    minor: Can't get value
  #006: ../../../src/H5PL.c line 397 in H5PL__find(): can't open directory
    major: Plugin for dynamically loaded library
    minor: Can't open directory or file
ERROR 1: H5Dread() failed for block.
ERROR 1: HDF5:/export/GIO/gww-probav-test/modis/2014/01/21/MC10GWW_X22Y09_20140121_1KM.HDF5://HUE, band 1: IReadBlock failed at X offset 0, Y offset 0
ERROR 1: GetBlockRef failed at X block offset 0, Y block offset 0

Any idea of what is wrong or how should I convert those data?

like image 693
Wraf Avatar asked Dec 11 '22 06:12

Wraf


2 Answers

gdal_translate your_HDF_file -sds output.tif

The -sds option will split your multiband HDF5 file into multiple single band tif files.

like image 83
Generic Wevers Avatar answered Dec 28 '22 07:12

Generic Wevers


Using R and gdal_translate:

library(gdalUtils)

band <- 1

file_path <- "/myfolder/myfile.hdf"

system(paste0('gdal_translate ', get_subdatasets(file_path)[band],' myfile_', band','.tif'))
like image 41
DJack Avatar answered Dec 28 '22 08:12

DJack