Loading MODIS HDF4 files with ArchGDAL

I would like to port to Julia some code that we have that works on MODIS satellite imagery. The source files are in HDF4 format, and are correctly recognized as MODIS datasets by the system gdalinfo. However, if I try loading them in Julia using ArchGDAL I get the error

AG.read("MOD03.A2019309.1035.061.NRT.hdf")
ERROR: GDALError (CE_Failure, code 4):
        `MOD03.A2019309.1035.061.NRT.hdf' not recognized as being in a supported file format.

My understanding is that this is coming directly from the GDAL library used by ArchGDAL, which is apparently compiled without HDF4 support (indeed, find(x -> startswith(x, "HDF"), AG.listdrivers()) only lists HDF5).

So, assuming I would like to have ArchGDAL come with HDF4 support, what would be my best course of action? Would it be possible to have my ArchGDAL be built against my system gdal so that the supported systems match?

Alternatively, since I’ve found that the feature has already been requested for GDAL.jl (which, IIUC, ArchGDAL depends on) Compile with HDF4 driver · Issue #84 · JuliaGeo/GDAL.jl · GitHub and a PR has been drafted a few months ago
[GDAL] Add HDF4 support to GDAL by asinghvi17 · Pull Request #9377 · JuliaPackaging/Yggdrasil · GitHub
what would be the best approach to work with a locally patched GDAL, pending an upstream integration of that same patch?

You may have a try with RemoteS. It also uses GDAL under the hood.

Edit: Oh, I read too quickly the HDF4 part. My local GDAL build has HDF4 support by I guess I never tried it with the Julia artifacts.

Yeah, the HDF4 thing is turning out to be surprisingly complicated.

There’s ongoing work here [GDAL] Bump v3.10.2 by jeremiahpslewis · Pull Request #10534 · JuliaPackaging/Yggdrasil · GitHub and apparently it has recently emerged that there were odd build interactions between HDF4, NetCDF and GDAl, see also HDF4: Build without NetCDF support by eschnett · Pull Request #10712 · JuliaPackaging/Yggdrasil · GitHub

So progress is slow, but is happening. I guess it’s just a matter of patience on my side :sunglasses:

The GDAL build now supports HDF4! Since this PR the GDAL_jll.jl starting from v302.1000.200 supports it. I just verified I can open a MODIS file with ArchGDAL.jl.

4 Likes

I just got an email from the GitHub thread and was just setting up to test, and then saw this message. I’m quite happy :sunglasses:

Thanks for pushing this @visr. Would you maybe share your code? I tried to access MODIS data, I can open the file with ArchGDAL,

const AG = ArchGDAL
filename = "MYD11C1.A2005352.006.2015269073039.hdf"
ds = AG.read(filename)
GDAL Dataset (Driver: HDF4/Hierarchical Data Format Release 4)
File(s): 
 MYD11C1.A2005352.006.2015269073039.hdf

but it does not seem to contain any raster layers.

AG.nlayer(ds), AG.nraster(ds)
(0, 0)

When opening the same file using PyNio it can see several layers of raster data. Can you confirm that you can actually extract data from your modis file?

Oh I didn’t try to access the data. Just tried your example with my MODIS file and I got the same…