3

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?

0

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

1
  • Why exactly? How does this fix the issue? Nov 17 '20 at 16:58

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.