BwUniCluster2.0/Software/R/Rgdal: Difference between revisions
No edit summary |
|||
(15 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
= Installation instructions = |
|||
<span style="color:red"><b>Note that the instructions provided below refer to R 4.2.1 (but not R 4.3.3)! We are currently updating our guides for R 4.3.3.</b></span> |
|||
Consider starting an interactive job for compiling. Copy and paste the following to your shell. |
|||
= General information = |
|||
<span style="color:red"><b>Note that rgdal and rgeos have been retired by their developers in 2023!</b> Please find further information at [https://cran.r-project.org/web/packages/rgdal/index.html https://cran.r-project.org/web/packages/rgdal/index.html] and [https://cran.r-project.org/web/packages/rgeos/index.html https://cran.r-project.org/web/packages/rgeos/index.html]. </span> |
|||
<b>Follow the instructions provided under [[bwUniCluster2.0/Software/R/terra]] to install the alternatives terra and sf.</b> |
|||
<span style="color:red"><b>Installing rgdal and rgeos is, however, still possible using the instructions below.</b></span> |
|||
rgdal and rgeos allows to use the following tools for handling spatial structures in R |
|||
* the 'Geospatial' Data Abstraction Library [https://gdal.org/ GDAL] |
|||
* Projection/transformation operations from the [https://proj.org/ PROJ] library |
|||
* Interface to the open source Geometry Engine [https://libgeos.org/ GEOS] |
|||
= Installation = |
|||
Please enter the following code, presented in the boxes below, directly into your shell/command line on bwUniCluster. |
|||
== Install external programs == |
|||
First, we download the sources of GDAL, PROJ, GEOS and install the three programs. |
|||
We will gather them in a folder src, unpack there and then compile. |
|||
We strongly recommend to use a interactive session with multiple cores. |
|||
<pre> |
|||
salloc -n 4 -t 30 -p dev_single |
|||
</pre> |
|||
First, provide the source directory (if not yet existing) |
|||
<pre> |
<pre> |
||
module load math/R |
|||
# Get sources |
|||
mkdir -p ~/src |
mkdir -p ~/src |
||
cd ~/src |
cd ~/src |
||
</pre> |
|||
wget http://download.osgeo.org/gdal/2.2.2/gdal-2.2.2.tar.gz |
|||
wget http://download.osgeo.org/geos/geos-3.6.2.tar.bz2 |
|||
wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz |
|||
# Not using git version |
|||
#git clone https://github.com/OSGeo/proj.4.git |
|||
Then, download and install PROJ |
|||
# Build gdal |
|||
<pre> |
|||
tar xf gdal-2.2.2.tar.gz |
|||
PROJ_VER=6.3.2 |
|||
wget http://download.osgeo.org/proj/proj-$PROJ_VER.tar.gz |
|||
./configure --prefix=$HOME/sw |
|||
tar xf proj-$PROJ_VER.tar.gz |
|||
make -j4 |
|||
cd proj-$PROJ_VER |
|||
./configure --prefix=$HOME/sw/R |
|||
make -j 8 |
|||
make install |
make install |
||
cd .. |
cd .. |
||
</pre> |
|||
Then, install gdal |
|||
# Build geos |
|||
tar xf geos-3.6.2.tar.bz2 |
|||
<pre> |
|||
cd geos-3.6.2 |
|||
GDAL_VER=3.4.1 |
|||
./configure --prefix=$HOME/sw |
|||
wget http://download.osgeo.org/gdal/$GDAL_VER/gdal-$GDAL_VER.tar.gz |
|||
make -j4 |
|||
tar xf gdal-$GDAL_VER.tar.gz |
|||
cd gdal-$GDAL_VER |
|||
./configure --prefix=$HOME/sw/R --with-proj=$HOME/sw/R |
|||
make -j 8 |
|||
make install |
make install |
||
cd .. |
cd .. |
||
</pre> |
|||
Finally, install GEOS |
|||
# Build proj.4 |
|||
<pre> |
|||
# Not using git version |
|||
GEOS_VER=3.9.2 |
|||
#cd proj.4 |
|||
wget http://download.osgeo.org/geos/geos-$GEOS_VER.tar.bz2 |
|||
#git checkout 4.9.3 -b 4.9.3 |
|||
tar xf geos-$GEOS_VER.tar.bz2 |
|||
#git branch |
|||
cd geos-$GEOS_VER |
|||
#autoreconf -i |
|||
./configure --prefix=$HOME/sw/R |
|||
tar xf proj-4.9.3.tar.gz |
|||
make -j 8 |
|||
cd proj-4.9.3 |
|||
./configure --prefix=$HOME/sw |
|||
make -j4 |
|||
make install |
make install |
||
cd .. |
cd .. |
||
</pre> |
|||
== Installing the R packages == |
|||
# Set up environment (you may want to put these lines in your ~/.bashrc as well) |
|||
export PATH=$PATH:$HOME/sw/bin |
|||
In order to install the two R packages, we need R to understand where we installed the 3 underlying programs, so we export the necessary paths. |
|||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/sw/lib |
|||
export MANPATH=$MANPATH:$HOME/sw/man |
|||
<pre> |
|||
export GDAL_DATA=$HOME/sw/share/gdal |
|||
export |
export LD_LIBRARY_PATH=$HOME/sw/R/lib:$LD_LIBRARY_PATH |
||
export PATH=$PATH:$HOME/sw/R/bin |
|||
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/sw/R/lib/pkgconfig |
|||
export GDAL_DATA=$HOME/sw/R/share/gdal |
|||
</pre> |
|||
Additionally, the R package installation features compilation of built-in C++ code, for which we specify compilation options ('compiler flags') |
|||
<pre> |
|||
export CFLAGS=-I$HOME/sw/R/include |
|||
export CXX="icpc -std=c++11" |
|||
export CXX17=icpc |
|||
</pre> |
|||
Now, we install rgdal and rgeos from within R. Note that, since we install a package from a local repository the order of the package installation is relevant. Installing rgdal will fail if sp is not available. |
|||
<pre> |
|||
module load math/R/4.1.2 |
|||
cd |
|||
wget https://cran.r-project.org/src/contrib/Archive/rgdal/rgdal_1.6-4.tar.gz |
|||
wget https://cran.r-project.org/src/contrib/Archive/rgeos/rgeos_0.6-1.tar.gz |
|||
# Install rgdal and rgeos packages from within R session |
|||
R -q |
R -q |
||
> install.packages("sp", repos="https://ftp.gwdg.de/pub/misc/cran/") |
|||
# Problem with too many arguments |
|||
> install.packages("~/rgdal_1.6-4.tar.gz", repos=NULL, type="source") |
|||
#install.packages("rgdal", configure.args = c("--with-proj-include=~/sw/include", "--with-proj-lib=~/sw/lib", "--with-proj-share=~/sw/share/proj")) |
|||
install.packages(" |
> install.packages("~/rgeos_0.6-1.tar.gz", repos=NULL, type="source") |
||
install.packages("rgeos") |
|||
library("rgdal") |
> library("rgdal") |
||
library("rgeos") |
> library("rgeos") |
||
</pre> |
</pre> |
||
== Preparations to use the rgdal/rgeos packages == |
|||
Since rgdal and rgeos depend on the external programs we installed, several environment variables have to be set before using the packages to allow R to address these programs. |
|||
We recommend to add the export commands |
|||
<pre> |
|||
export LD_LIBRARY_PATH=$HOME/sw/R/lib:$LD_LIBRARY_PATH |
|||
export PATH=$PATH:$HOME/sw/R/bin |
|||
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/sw/R/lib/pkgconfig |
|||
export GDAL_DATA=$HOME/sw/R/share/gdal |
|||
</pre> |
|||
to your [[BwUniCluster_2.0_Slurm_common_Features#sbatch_Examples | batch job scripts]] that use rgdal and rgeos or to run them directly in the command line if you use an [[BwUniCluster_2.0_Batch_Queues | interactive session]]. |
Latest revision as of 09:53, 18 June 2024
Note that the instructions provided below refer to R 4.2.1 (but not R 4.3.3)! We are currently updating our guides for R 4.3.3.
General information
Note that rgdal and rgeos have been retired by their developers in 2023! Please find further information at https://cran.r-project.org/web/packages/rgdal/index.html and https://cran.r-project.org/web/packages/rgeos/index.html.
Follow the instructions provided under bwUniCluster2.0/Software/R/terra to install the alternatives terra and sf.
Installing rgdal and rgeos is, however, still possible using the instructions below.
rgdal and rgeos allows to use the following tools for handling spatial structures in R
- the 'Geospatial' Data Abstraction Library GDAL
- Projection/transformation operations from the PROJ library
- Interface to the open source Geometry Engine GEOS
Installation
Please enter the following code, presented in the boxes below, directly into your shell/command line on bwUniCluster.
Install external programs
First, we download the sources of GDAL, PROJ, GEOS and install the three programs.
We will gather them in a folder src, unpack there and then compile.
We strongly recommend to use a interactive session with multiple cores.
salloc -n 4 -t 30 -p dev_single
First, provide the source directory (if not yet existing)
mkdir -p ~/src cd ~/src
Then, download and install PROJ
PROJ_VER=6.3.2 wget http://download.osgeo.org/proj/proj-$PROJ_VER.tar.gz tar xf proj-$PROJ_VER.tar.gz cd proj-$PROJ_VER ./configure --prefix=$HOME/sw/R make -j 8 make install cd ..
Then, install gdal
GDAL_VER=3.4.1 wget http://download.osgeo.org/gdal/$GDAL_VER/gdal-$GDAL_VER.tar.gz tar xf gdal-$GDAL_VER.tar.gz cd gdal-$GDAL_VER ./configure --prefix=$HOME/sw/R --with-proj=$HOME/sw/R make -j 8 make install cd ..
Finally, install GEOS
GEOS_VER=3.9.2 wget http://download.osgeo.org/geos/geos-$GEOS_VER.tar.bz2 tar xf geos-$GEOS_VER.tar.bz2 cd geos-$GEOS_VER ./configure --prefix=$HOME/sw/R make -j 8 make install cd ..
Installing the R packages
In order to install the two R packages, we need R to understand where we installed the 3 underlying programs, so we export the necessary paths.
export LD_LIBRARY_PATH=$HOME/sw/R/lib:$LD_LIBRARY_PATH export PATH=$PATH:$HOME/sw/R/bin export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/sw/R/lib/pkgconfig export GDAL_DATA=$HOME/sw/R/share/gdal
Additionally, the R package installation features compilation of built-in C++ code, for which we specify compilation options ('compiler flags')
export CFLAGS=-I$HOME/sw/R/include export CXX="icpc -std=c++11" export CXX17=icpc
Now, we install rgdal and rgeos from within R. Note that, since we install a package from a local repository the order of the package installation is relevant. Installing rgdal will fail if sp is not available.
module load math/R/4.1.2 cd wget https://cran.r-project.org/src/contrib/Archive/rgdal/rgdal_1.6-4.tar.gz wget https://cran.r-project.org/src/contrib/Archive/rgeos/rgeos_0.6-1.tar.gz R -q > install.packages("sp", repos="https://ftp.gwdg.de/pub/misc/cran/") > install.packages("~/rgdal_1.6-4.tar.gz", repos=NULL, type="source") > install.packages("~/rgeos_0.6-1.tar.gz", repos=NULL, type="source") > library("rgdal") > library("rgeos")
Preparations to use the rgdal/rgeos packages
Since rgdal and rgeos depend on the external programs we installed, several environment variables have to be set before using the packages to allow R to address these programs.
We recommend to add the export commands
export LD_LIBRARY_PATH=$HOME/sw/R/lib:$LD_LIBRARY_PATH export PATH=$PATH:$HOME/sw/R/bin export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/sw/R/lib/pkgconfig export GDAL_DATA=$HOME/sw/R/share/gdal
to your batch job scripts that use rgdal and rgeos or to run them directly in the command line if you use an interactive session.