首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在OSX / MAC上绑定GDAL与R-不能打开/浏览R中的h4文件

在OSX / MAC上绑定GDAL与R-不能打开/浏览R中的h4文件
EN

Stack Overflow用户
提问于 2017-08-09 19:04:11
回答 1查看 912关注 0票数 2

不知何故,我在我的macbook上搞砸了一个gdal安装。以前,代码用于在H4中打开和操作R文件(.hdf)。同样的代码也能在我的桌面上运行。然而,现在,代码工作在我的桌面上,而不是我的笔记本电脑。同样的密码。同样的数据。

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

现在,如果我在Bash命令行中对hdf文件运行gdalinfo,那么它读取该文件就很好了。但是,如果我在R中运行这段代码--使用GDALutils函数get_subdatasets():

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

它返回错误:

代码语言:javascript
复制
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 
代码语言:javascript
复制
similarly using another package - rgdal I run the function,  `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` 

I realize these are two different packages and associated functions. 

I found this post:

- [https://gis.stackexchange.com/questions/199647/hdf-files-in-gdal-throwing-an-error-in-r-gdalinfo](https://gis.stackexchange.com/questions/199647/hdf-files-in-gdal-throwing-an-error-in-r-gdalinfo) 

but the code `gdal_chooseInstallation(hasDrivers=c("HDF4","HDF5"))` 

returns 

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

NOTE: Interestingly this same code on my desktop (that is able to read the files in R) also returns an error even though it can find the drivers). 

Naturally I know that the drivers exist on my computer because I am able to explore h4 files at the command line outside of R. And I know my code is just fine because it works on my desktop on the same data with the same directory structure.

Any ideas how I can clean my gdal slate on my mac to remove potential conflicts OR to direct R to the correct gdal version (i am not sure what that version is however!)? This is something specific associated with binding gdal to R that i'm not sure how to tackle.

UPDATE:  Running this in R:

`system("gdalinfo --version")`

Returns: 

`GDAL 1.11.5, released 2016/07/01`

Yet at the command line

`gdalinfo --version`

Returns 

`GDAL 2.1.0, released 2016/04/25`

Thank you for any leads... Leah 

UPDATES: i have finally figured out how to link and unlink gdal 2 vs 2 and i have figured out how to use brew to install hdf4 however at this point, i can't reinstall gdal2 

I am using the tutorial here:

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

This worked yesterday but then i needed to install the h4 libraries to i removed gdal2

```javascript

brew删除gdal2

安装h4库

brew安装hdf4

代码语言:javascript
复制
And then tried to reinstall following the directions in the tutorial.

Here is what i get at this point

```javascript

$ brew安装gdal2

代码语言:javascript
复制
OUTPUT:

```javascript

==>从osgeo/osgeo4mac安装gdal2

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

警告:使用cfitsio代替已废弃的自制/science/cfitsio

==>使用Homebrew提供的fortran编译器。

这可以通过设置FC环境变量来更改。

==>下载http://download.osgeo.org/gdal/2.2.1/gdal-2.2.1.tar.gz

已下载: /Users/leah-su/Library/Caches/Homebrew/gdal2-2.2.1.tar.gz

==> ./configure前缀=/usr/local/c业力/gdal2 2/2.2.1-下颌骨=/usr/local/Cella

来自/Users/leah-su/Library/Logs/Homebrew/gdal2/01.configure:的最后15行

检查SDget_maxopenfiles在-lmfhdf..。是

检查H5Fopen在-lhdf5..。是

检查kea-config.不是

去找凯..。不是

检查nc-config./usr/local/bin/

使用nc检查libnetcdf编译器和链接器标志.

得到version="netCDF 4.4.1.1",prefix=“/usr/local/c业力/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“

检查nc_open在-lnetcdf..。是

在libnetcdf中检查netcdf-4 (和HDF5)支持。是

检查libnetcdf中的HDF4支持。不是

配置:使用/usr/local中的JasPer库。

检查jp2_encode_uuid在-ljasper..。不是

配置:未找到被黑的JasPer版本,GeoJP2已禁用。

配置:错误: openjpeg.h未在/usr/local/include/openjpeg-2.0或/usr/local/include/openjpeg-2.1中找到

如果报告这一问题,请在以下地点(不是Homebrew/brew或Homebrew/core)这样做:

https://github.com/osgeo/homebrew-osgeo4mac/issues

这些未决问题也可能有助于:

brew安装osgeo/osgeo4mac/gdal2-mrsid失败https://github.com/OSGeo/homebrew-osgeo4mac/issues/250

使用公共标志gdal2生成https://github.com/OSGeo/homebrew-osgeo4mac/issues/245失败

无法在OS 10.12.6 https://github.com/OSGeo/homebrew-osgeo4mac/issues/252上升级https://github.com/OSGeo/homebrew-osgeo4mac/issues/252

请在gdal2公式https://github.com/OSGeo/homebrew-osgeo4mac/issues/220中添加--没有-pdfium选项。

使用osGeo4mac的gdal2与自制核心的后置https://github.com/OSGeo/homebrew-osgeo4mac/issues/185

gdal1-mrsid和gdal2-mrsid无法构建https://github.com/OSGeo/homebrew-osgeo4mac/issues/213

代码语言:javascript
复制
EN

回答 1

Stack Overflow用户

发布于 2017-08-10 22:21:43

好的..。对于外面的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

当您安装gdal -R时,查找最新安装的版本并默认使用该版本。但是,可以在.bash_profile文档中指定所需的生成。此外,国王混沌分布-它有gdal 2.1确实支持h4。所以我所做的:

  1. 转到KyngChaos并获得GDAL2.1完整的发行版。陶醉于与此网站相关的尖端网站设计:)
  2. 在mac上安装gdal complete 2.1
  3. 接下来,通过shell打开您的.bash_profile (它是一个隐藏文件)
代码语言:javascript
复制
```javascript

转到bash中的主目录

代码语言:javascript
复制
cd  
代码语言:javascript
复制
# open .bash_profile using your favorite text editor and whatever shortcut you have setup
代码语言:javascript
复制
vim .bash_profile
代码语言:javascript
复制
# add path to gdal to your profile (copy and paste or do it via shell)
代码语言:javascript
复制
export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH
代码语言:javascript
复制
# save and close 
代码语言:javascript
复制

最后--清理R中的东西,如果你使用的是gdalUtils和rgdal,一定要同时删除两者。删除它们,然后重新安装。重启R.

现在一切都应该正常了。希望这能帮助其他人解决同样的问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45598772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档