2017-08-09 132 views
1

我在某种程度上搞砸了我的Macbook上的gdal安装。以前的代码工作在R中打开和操作H4文件(.hdf)。并且相同的代码在我的桌面上工作。但是,现在,代码在我的桌面上运行,而不是我的笔记本电脑。相同的代码。相同的数据。在OSX/MAC上绑定GDAL与R - 无法打开/探索R中的h4文件

我怀疑这与试图通过conda安装gdal支持python有关。

现在,如果我在bash的命令行上运行hdf文件中的gdalinfo,它会读取文件。但是,如果我在R运行此代码 - 使用GDALutils功能get_subdatasets():

get_subdatasets("MOD09GA.A2016199.h09v05.006.2016201065406.hdf")

它返回的错误:

ERROR 4: `data/week6/modis/reflectance/17_july_2016/MOD09GA.A2016199.h09v05.006.2016201065406.hdf' not recognised as a supported file format. 

gdalinfo failed - unable to open 'data/week6/modis/reflectance/17_july_2016/MOD09GA.A2016199.h09v05.006.2016201065406.hdf'. 
Error in split1[[1]] : subscript out of bounds 
In addition: Warning message: 
running command '"/usr/local/Cellar/gdal/1.11.5_3/bin/gdalinfo" "data/week6/modis/reflectance/17_july_2016/MOD09GA.A2016199.h09v05.006.2016201065406.hdf"' had status 1 

```

同样使用另一个包 - rgdal我运行的功能,gdalinfo()

Warning message: running command '"/usr/local/Cellar/gdal/1.11.5_3/bin/gdalinfo" "data/week6/modis/reflectance/17_july_2016/MOD09GA.A2016199.h09v05.006.2016201065406.hdf"' had status 1

我意识到这些是两个不同的包和相关的功能。

我发现这个职位:

但代码gdal_chooseInstallation(hasDrivers=c("HDF4","HDF5"))

回报

Error in gdal_chooseInstallation(hasDrivers = c("HDF4", "HDF5")) : No installations match.

注:有趣的是这同我的桌面上的代码(即能够读取R中的文件)也会返回一个错误,即使它可以找到驱动程序)。

当然,我知道驱动程序存在于我的电脑上,因为我能够在R之外的命令行探索h4文件。而且我知道我的代码很好,因为它可以在我的桌面上使用相同的数据相同的目录结构。

任何想法如何我可以在我的Mac上清理我的gdal石板以消除潜在的冲突或将R引导至正确的gdal版本(但我不确定那是什么版本!)?这是与gdal绑定到R的具体关联,我不知道如何解决。

UPDATE: R中运行该:

system("gdalinfo --version")

返回:

GDAL 1.11.5, released 2016/07/01

然而在命令行

gdalinfo --version

返回

GDAL 2.1.0, released 2016/04/25

谢谢你的任何线索...... 利亚

更新: 我终于想通了如何对2链接和取消链接@中2,我已经想通了如何使用BREW在这一点上却安装HDF4,我不能重新安装gdal2

我使用此教程:

https://www.karambelkar.info/2016/10/gdal-2-on-mac-with-homebrew/

这昨天的工作,但后来我需要安装H4库我删除gdal2

brew remove gdal2 
# install h4 libraries 
brew install hdf4 

,然后试图重新安装教程中的说明。

这里是我所得到的在这一点上

$ brew install gdal2 --with-armadillo --with-complete --with-libkml --with-unsupported 

OUTPUT:

==> Installing gdal2 from osgeo/osgeo4mac 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
Warning: Use cfitsio instead of deprecated homebrew/science/cfitsio 
==> Using Homebrew-provided fortran compiler. 
This may be changed by setting the FC environment variable. 
==> Downloading http://download.osgeo.org/gdal/2.2.1/gdal-2.2.1.tar.gz 
Already downloaded: /Users/leah-su/Library/Caches/Homebrew/gdal2-2.2.1.tar.gz 
==> ./configure --prefix=/usr/local/Cellar/gdal2/2.2.1 --mandir=/usr/local/Cella 
Last 15 lines from /Users/leah-su/Library/Logs/Homebrew/gdal2/01.configure: 
checking for SDget_maxopenfiles in -lmfhdf... yes 
checking for H5Fopen in -lhdf5... yes 
checking for kea-config... no 
checking for kea... no 
checking for nc-config... /usr/local/bin/nc-config 
checking libnetcdf compiler and linker flags with nc-config... 
got version="netCDF 4.4.1.1", prefix="/usr/local/Cellar/netcdf/4.4.1.1_6", 
libs="-L/usr/local/Cellar/netcdf/4.4.1.1_6/lib -lnetcdf -lhdf5_hl -lhdf5 -lsz -lz -ldl -lm -lcurl", includedir="/usr/local/Cellar/netcdf/4.4.1.1_6/include" 
checking for nc_open in -lnetcdf... yes 
checking for netcdf-4 (and HDF5) support in libnetcdf... yes 
checking for HDF4 support in libnetcdf... no 
configure: using JasPer library from /usr/local. 
checking for jp2_encode_uuid in -ljasper... no 
configure: hacked JasPer version not found, GeoJP2 disabled. 
configure: error: openjpeg.h not found in /usr/local/include/openjpeg-2.0 or /usr/local/include/openjpeg-2.1 

If reporting this issue please do so at (not Homebrew/brew or Homebrew/core): 
https://github.com/osgeo/homebrew-osgeo4mac/issues 

These open issues may also help: 
brew install osgeo/osgeo4mac/gdal2-mrsid fails https://github.com/OSGeo/homebrew-osgeo4mac/issues/250 
Failed to build gdal2 with common flags https://github.com/OSGeo/homebrew-osgeo4mac/issues/245 
Cannot upgrade gdal2 on OS X 10.12.6 https://github.com/OSGeo/homebrew-osgeo4mac/issues/252 
Please add --without-pdfium option to gdal2 formula https://github.com/OSGeo/homebrew-osgeo4mac/issues/220 
Using osgeo4mac's gdal2 with homebrew core's postgis https://github.com/OSGeo/homebrew-osgeo4mac/issues/185 
gdal1-mrsid and gdal2-mrsid fails to build https://github.com/OSGeo/homebrew-osgeo4mac/issues/213 

```

回答

1

好吧......为MAC用户在那里,我还终于解决了这个问题。 如果您使用brew配方代码,您会注意到通过brew安装gdal时不支持hdf4。

这就是我在代码中遇到的情况。我认为同样的conda生成也可能与osgeo/4mac类似。

https://github.com/Homebrew/homebrew-core/blob/master/Formula/gdal.rb

https://github.com/OSGeo/homebrew-osgeo4mac

当您安装@中 - R的查找最近安装的版本,并使用在默认情况下。但是,您可以在.bash_profile文档中指定所需的构建版本。另外King Chaos发行版 - 它有gdal 2.1支持h4。所以我做了什么:

  1. 转向KyngChaos并获得GDAL 2.1完整分布。陶醉在与本网站相关的最前沿的网站设计:)
  2. 在您的mac上安装gdal complete 2.1
  3. 接下来,打开您的。通过外壳的.bash_profile(这是一个隐藏文件)

```

# go to your home directory in bash 
    cd 
    # open .bash_profile using your favorite text editor and whatever shortcut you have setup 
    vim .bash_profile 
    # add path to gdal to your profile (copy and paste or do it via shell) 
    export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH 
    # save and close 

```

最后 - 干净的东西在R.如果你使用gdalUtils和rgdal是务必删除两个。删除它们然后重新安装。重新启动R.

一切都应该现在的工作。希望这可以帮助有同样问题的其他人。