TransWikia.com

runGdal returns "gdalinfo failed - unable to open" [...] ".hdf" file

Geographic Information Systems Asked on July 9, 2021

I’m trying to use the function runGdalin R on a Mac and it seems that gdalinfo is not able to open the file.

In the terminal, when I entered
gdalinfo /MODIS/MCD12Q1.006/2009.01.01/MCD12Q1.A2009001.h10v05.006.2018054191941.hdf

I got the following:

Driver: HDF4/Hierarchical Data Format Release 4
Files: /MODIS/MCD12Q1.006/2009.01.01/MCD12Q1.A2009001.h10v05.006.2018054191941.hdf
Size is 512, 512
Coordinate System is `'
Metadata:
[...]

So GDAL seems to be working (version of gdalinfo: GDAL 2.1.3, released 2017/20/01). But in R, it doesn’t seem to be recognized.

In R, I set up the path to GDAL like this:

MODISoptions(MODISserverOrder = c("LAADS", "LPDAAC"), 
             localArcPath = "my.path", 
             outDirPath = "my.path",
             gdalPath = "/Library/Frameworks/GDAL.framework/Versions/Current/Programs/", 
             quiet = FALSE)

Running this in terminal showed that HDF4 is supported:

gdalinfo --formats
  [...]
  HDF4Image -raster- (rw+): HDF4 Dataset
  [...]

In R, I typed system("gdalinfo --version") and got back GDAL 2.4.1, released 2019/03/15

system("gdalinfo                                                              /path.to.my.hdf")

ERROR 4: `... .hdf' not recognized as a supported file format.
gdalinfo failed - unable to open '... .hdf'.

system("/Library/Frameworks/GDAL.framework/Versions/Current/Programs/gdalinfo /path.to.my.hdf")

This last line one worked (with the full path to gdal)! But how to make it work in runGdal?

Is there a way to make the runGdal function work in R on a Mac?

One Answer

You need to uninstall gdalinfo on your mac environment and use R gdalinfo and dont forget to restart your R after uninstall it

Answered by dunno2121 on July 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP