I need to visualize some area using values provided in HDF-EOS version 5 file and create map using those values and other GIS layers. Unfortunately, my QGIS do not recognize the HDF5 file.

Do I really need to compile GDAL manually as described at: SciGeo?

Maybe there's an easier way to do that? I thought about conversion to the GeoTIFF. However HEG tool crashes during conversion.

I opened my product in HDFView, but I don't see any option to generate GeoTIFF in this application.

Last, but not least, I've tried R! I read appropriate data set, but I don't know what to do next. Is there any possibility to save this data in different format? Or maybe I am able to (how? I can't find this in h5 package documentation)

My current code is:


# download HDF-5 file
destfile <- 'SMAP.h5'

# read file
file <- h5file(destfile ,'r')
dataset <- file["Soil_Moisture_Retrieval_Data"]["soil_moisture"]

# @Spacedman: Does your R have a GDAL that supports these files?
# it outputs:
#         name    long_name create  copy
# 51 HDF4Image HDF4 Dataset   TRUE FALSE
# 53 HDF5Image HDF5 Dataset  FALSE FALSE
  • Can you link to a data file please? – Spacedman Jul 2 '16 at 16:25
  • Does your R have a GDAL that supports these files? If so, you can use the raster package to read them. subset(rgdal::gdalDrivers(),grepl("HDF",long_name)) will look for HDF drivers. – Spacedman Jul 2 '16 at 16:54
  • h5 is incredibly raw, you have pull everything out manually with its low level functions, including dimension sizes. Otherwise, Linux rgdal with HDF5 is easy, on Windows probably best to convert to GTiff with OSGeo4W – mdsumner Jul 2 '16 at 19:34
  • @Spacedman: I edited my code sample to read data from FTP. – matandked Jul 3 '16 at 13:56
  • @AndreJ Generally speaking, I used mentioned approach (use gdal_translate to convert it to GeoTIFF). Could you post it as an answer? – matandked Nov 21 '16 at 14:38

That particular file, or at least that particular dataset within that file, is not a regular grid, and so can't be converted (easily) to a GeoTIFF file or read in as a raster data source.

> long <- file["Soil_Moisture_Retrieval_Data"]["longitude"]
> str(long)
Formal class 'DataSet' [package "h5"] with 7 slots
  ..@ name       : chr "longitude"
  ..@ datatype   : chr "d"
  ..@ dim        : num 297120
  ..@ maxdim     : num 297120
  ..@ chunksize  : num 297120
  ..@ compression: chr "H5Z_FILTER_DEFLATE"
  ..@ pointer    :<externalptr> 

You can use ReadDataSet to get the data:

> lat <- readDataSet(file["Soil_Moisture_Retrieval_Data"]["latitude"])
> long <- readDataSet(file["Soil_Moisture_Retrieval_Data"]["longitude"])
> moisture <- readDataSet(file["Soil_Moisture_Retrieval_Data"]["soil_moisture"])

What you now have is three long vectors of long, lat, moisture values. If you plot(long,lat) you'll see how these points look like they come from a pass of the satellite over a certain part of the globe, and so can't be made into a regular grid without it being 90% missing data.

I think that if you wanted a small square of data within the satellite pass then that might be convertible to a raster - if the above works for you and you can't work out how to subset it then open a new question - this answer should suffice for how to extract data in general from these files.

Note most of my info on this I got from running h5dump, h5ls and h5stat on the file from the Linux command line.

  • 1
    I think that your answer is very helpful to understand the nature of the problem, but doesn't respond to the question about creating map/visualization. As mentioned in comments, I ended up with using GDAL tools for converting HDF to GeoTIFF which might be easily visualized. – matandked Nov 21 '16 at 14:46

You can find a solution to read the data at Opening data from NSIDC in QGIS?.

SMAP L2 files work with Panoply, while SMAP L3 is readable with GDAL.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.