rgdal package installation

The issue here is not exactly how to plot maps through R, as I have found already a pretty nice example here, but rather how to make it work. In fact, I am unable to load library rgdal:

library(rgdal)
Error in library(rgdal) : there is no package called ‘rgdal’

However, when I try to install the above package manually, I get the following error:

....
configure: error: proj_api.h not found in standard or given locations.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/home/eualin/R/i686-pc-linux-gnu-library/2.15/rgdal’
Warning in install.packages : installation of package ‘/home/eualin/Downloads/rgdal_0.8-5.tar.gz’ had non-zero exit status

Any input welcome!

94969 次浏览

I f you look at the CRAN 上的软件包页面, you will see the following :

系统需求: 从源代码构建: GDAL > = 1.7.1库 来自 http://trac.osgeo.org/gdal/wiki/DownloadSource和来自 http://trac.osgeo.org/proj/的 PROJ.4(PROJ > = 4.4.9) ; 由 William Kyngesburye 在 http://www.kyngchaos.com/构建的 GDAL OSX 框架可用于 源代码安装在 OSX 上。

正如您似乎在 Linux 下一样,您总是从源代码构建包,因此您必须在系统上安装相应的库。如果你使用的是 Mint,Ubuntu 或者其他 Debian 衍生版本,你可以这样做:

$ sudo apt-get install libgdal1-dev libproj-dev

在 Debian 系统下,一个有用的技巧是安装 apt-file软件包并运行:

$ sudo apt-file update

然后,当出现以下错误时:

configure: error: proj_api.h not found in standard or given locations.

You can use the following command to find which package you must install to get the missing file :

$ apt-file search proj_api.h
libproj-dev: /usr/include/proj_api.h

这对我很有效:

install.packages('rgdal',repos="http://www.stats.ox.ac.uk/pub/RWin")

在 ubuntuStudio 14.04上(对所有 debian 发行版都是一样的) :

sudo apt-get install libproj-dev libgdal-dev

Then I could install package rgdal

R info:
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"


Linux info:
Linux francois-K53SV 3.13.0-34-lowlatency #60-Ubuntu SMP PREEMPT Wed Aug 13 16:15:18 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

如果在 自制包装管理器中使用 OS X,并且通过 自制科学水龙头安装了 R,那么可以通过首先安装 gdal 来安装 rgdal。

brew install gdal

You may first want to list the options available before you run this in case you want something 太棒了 like postgresql support. To see the available options type

brew options gdal

然后你就可以打字了

brew install --with-postgresql gdal

经过一段时间,你应该好去与依赖,因为 proj包括你所需要的 Proj _ api. h是依赖!不幸的是,rgdal 现在仍然找不到 pro _ api.h,因为它没有查找/usr/local/include。要修复此问题以及安装 rgdal 时可能出现的其他问题,请使用以下 < em > R 命令安装 rgdal:

  > install.packages('rgdal', type = "source", configure.args=c('--with-proj-include=/usr/local/include','--with-proj-lib=/usr/local/lib'))

This should be similar to what you would also need for MacPorts with the exception of the brew steps, and your libraries/headers are most likely under "/opt/local/lib" and "/opt/local/include" respectively.

注意: 如果在 gdal 中使用“-with-armadillo”作为选项,则酿造升级程序 ,并将犰狳从6升级到7。在升级/重新安装 rgdal 之前,必须重新编译 gdal。

The only thing that worked on my system was to compile PROJ4 from source as described 给你 and then instal the rgdal package as

 install.packages("rgdal")

在使用 R-3.2.0的 Fedora 21系统上,下面的代码可以工作:

yum install gdal.x86_64 gdal-devel.x86_64 gdal-libs.x86_64
yum install proj.x86_64 proj-devel.x86_64
yum install proj-epsg.x86_64 proj-nad.x86_64

显然,这是多次尝试得到的结果:

install.packages("rgdal")

to work. You can probably do it all in one install.

在 OSX 中,我从 http://www.kyngchaos.com/software/frameworks下载 proj 并在 R 中运行以下命令。

install.packages('rgdal', type = "source", configure.args=c('--with-proj-include=/Library/Frameworks/PROJ.framework/Headers', '--with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'))

这是我在 Centos7上做的:

yum install gdal gdal-devel
yum install proj-devel
yum install proj-nad
yum install proj-epsg

那就简单点

install.packages("rgdal")

工作很顺利,但一点也不清楚。

对于安装了多个版本的 proj (从源代码)的多用户环境中的人,我使用的方法是:

install.packages('rgdal',configure.args="--with-proj-include=/sw/proj/4.9.2/include --with-proj-lib=/sw/proj/4.9.2/lib")

对于 Mac (OS.X Version10.12.6)用户来说,这对我很有用。 首先,转到命令行,使用 > > brew install gdal安装 Gdal Second, got to Rstuduio(R console) and install the package using install.packages("rgdal")

For me (Ubuntu 16.04, R 3.4.2), a mixture of the above solutions worked:

sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev

Then simply installed rgdal from CRAN.

对于 ubuntu16.04和 R3.5.1,这个工作速度非常快:

sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt install gdal-bin python-gdal python3-gdal libgdal1-dev

Then;

sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev

最后在 CRAN;

install.packages("rgdal")

要解决这个问题,你需要 install libgdal-dev:

$sudo apt install libgdal-dev

None of the above answers worked for me (running R 3.5.1 on Linux Mint 17.1). GDAL version in the Ubuntu repositories is 1.11.3, this causes installation of rGDAL to fail. Here is the solution that worked for me (from 这个 website):

sudo apt-get install libexpat1-dev

下载并安装 GDAL

wget http://download.osgeo.org/gdal/2.1.1/gdal-2.1.1.tar.gz
tar xvf gdal-2.1.1.tar.gz
cd gdal-2.1.1
./configure
sudo make
sudo make install

确认版本

gdal-config --version

然后我得到了这个错误:

** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/usr/local/lib/R/site-library/rgdal/libs/rgdal.so':
libgdal.so.20: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed

This was fixed by updating the bindings:

sudo ldconfig

然后在 R 中运行 install.packages("rgdal")就可以了。

无法得到 rgdal 正确安装,我已经尝试了所有提到的和所有建议在这里 R not finding package even after package installation

library(rgdal)
rgdal: version: 1.4-3, (SVN revision 828)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/xxx/Documents/R/win-library/3.4/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/xxx/Documents/R/win-library/3.4/rgdal/proj
Linking to sp version: 1.3-1
Warning message:
package ‘rgdal’ was built under R version 3.4.4

我已经将我的 R 升级到了3.6

再试一次:

batch_gdal_translate(x, desc, outsuffix = "4.img", of = "HFA", co="TILED=YES")
NULL
Warning messages:
1: In gdal_setInstallation() :
No GDAL installation found. Please install 'gdal' before continuing:
- www.gdal.org (no HDF4 support!)
- www.trac.osgeo.org/osgeo4w/ (with HDF4 support RECOMMENDED)
- www.fwtools.maptools.org (with HDF4 support)


2: In gdal_setInstallation() : If you think GDAL is installed, please run:
gdal_setInstallation(ignore.full_scan=FALSE)

我曾经尝试在 RStudio & 命令行 R3.6.1 GUI 中运行这个程序。

all times I have tried this I get positive results for the libraries being installed.

library(raster)
Loading required package: sp
library(rgdal)
rgdal: version: 1.4-4, (SVN revision 833)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/xxx/Documents/R/R-3.6.1/library/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/xxx/Documents/R/R-3.6.1/library/rgdal/proj
Linking to sp version: 1.3-1
library(gdalUtils)
Registered S3 method overwritten by 'R.oo':
method        from
throw.default R.methodsS3

我试图读取的文件是 dted 文件?

x <- list.files(path = src, pattern = ".dt", full.names = TRUE)
length(x)


batch_gdal_translate(x, desc, outsuffix = "4.img", of = "HFA", co="TILED=YES")

I have tried the above with GTIFF .tif format also and I get the same error. 但是我没有尝试读取.hdf 文件,只是读取.dt0、 . dt1、 . dt2

这将工作在另一台机器上,我已经安装了 R,但是,我试图找出什么是错误的安装在“这台”机器上。

Explicitly adding the include path in CFLAGS worked for me

install.packages('rgdal', type = "source", configure.args=c('CFLAGS=-I/apps/proj4/5.2.0/include'))

如果你使用的是 MacPorts,这个应该可以:

  1. 安装 gdal(proj6将作为一个依赖项安装)

    sudo port install gdal
    
  2. Install pkg-config

    sudo port install pkgconfig
    
  3. Set PKG_CONIFG_PATH variable to point to a directory with proj.pc file. In my case this was:

    export PKG_CONFIG_PATH=/opt/local/lib/proj6/lib/pkgconfig
    

如果还有人对此有问题,我从这个网站得到了 rgdal 的一个版本:

Https://cran.r-project.org/web/packages/rgdal/index.html

并安装了它:

install.packages("filename.tar", repos = NULL, type = "source")

如果您正在使用 Conda 环境,请使用:

conda install -c conda-forge r-rgdal
conda install -c conda-forge/label/broken r-rgdal
conda install -c conda-forge/label/cf201901 r-rgdal
conda install -c conda-forge/label/cf202003 r-rgdal


conda install -c conda-forge proj