Installing rgdal_1.4-8.tar.gz with R-3.6.0 on CentOS 7


I tried installing rgdal_1.4.8.tar.gz with R-3.6.0  and there were a number of issues. Even though I have followed and installed according to “Compile gdal-2.4.3 on CentOS 7” I have the follow error.

Issue 1: Error: Proj.h not found in standard or given locations

.....
.....
checking C++11 support for GDAL >= 2.3.0... yes
checking GDAL version >= 1.11.4... yes
checking GDAL version <= 2.5.0... yes
checking gdal: linking with --libs only... yes
checking GDAL: gdal-config data directory readable... yes
checking GDAL: /usr/local/gdal-2.4.3/share/gdal/pcs.csv readable... yes
checking proj_api.h presence and usability... no
configure: error: proj_api.h not found in standard or given locations.
ERROR: configuration failed for package ‘rgdal’
.....

Apparently R is not able to find inside pkconfig for proj.pc file. To resolve it, do the following to your ~.bashrc environment.

export PKG_CONFIG_PATH=/usr/local/proj-5.2.0/lib/pkgconfig

You can verify by using the command

# pkg-config proj --libs
-L/usr/local/proj-5.2.0/lib -lproj

You can get more information via the thread proj_api.h not found in standard or given locations #1092

Issue 2: Proj_LIB Path Issues

.....
checking proj_api.h presence and usability... yes
checking PROJ version >= 4.8.0... yes
checking projects.h presence and usability... yes
checking PROJ.4: epsg found and readable... no
Error: proj/epsg not found
Either install missing proj support files, for example
the proj-nad and proj-epsg RPMs on systems using RPMs,
or if installed but not autodetected, set PROJ_LIB to the
correct path, and if need be use the --with-proj-share=
configure argument.
ERROR: configuration failed for package ‘rgdal’
.....

To resolve the PROJ_LIB Issue

export PROJ_LIB=/usr/local/proj-5.2.0/share/proj

You can more information from https://github.com/r-spatial/lwgeom/issues/28

Finally, you should be able to compile rgdal_1.4-8.tar.gz with R-3.6.0

# R CMD INSTALL rgdal_1.4-8.tar.gz
.....
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (rgdal)
.....

Final Step: Testing and Verification

Load both gdal and proj libaries. Make sure you have compile gdal and proj libraries using the tutorial Compile gdal-2.4.3 on CentOS 7

$ module load proj/5.2.0
$ module load R/3.6.0
$ module load gdal/2.4.3
$ R
library(rgdal)
Loading required package: sp
rgdal: version: 1.4-8, (SVN revision 845)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.4.3, released 2019/10/28
Path to GDAL shared files: /usr/local/gdal-2.4.3/share/gdal
GDAL binary built with GEOS: FALSE
Loaded PROJ.4 runtime: Rel. 5.2.0, September 15th, 2018, [PJ_VERSION: 520]
Path to PROJ.4 shared files: /usr/local/proj-5.2.0/share/proj
Linking to sp version: 1.3-2

 

This entry was posted in R. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.