In this guide, we'll walk through the steps to download, build, and configure the GDAL library, ensuring compatibility with the 'sf' package in R. This is particularly important when you're working with spatial data and need a specific version of GDAL to match the required version of the 'sf' package.
Step 1: Download GDAL Source Code
The first step is to download the GDAL source code. For this guide, we’ll use version 2.4.0, which is compatible with 'sf' package version '1.0.14'. To download it, follow these commands:
cd /tmp
wget https://download.osgeo.org/gdal/2.4.0/gdal-2.4.0.tar.gz
tar -xzf gdal-2.4.0.tar.gz
cd gdal-2.4.0
Step 2: Configure GDAL
Before building GDAL, you need to configure it according to your system's requirements. You can specify options based on what you need. Here’s a typical configuration command:
./configure --with-python --with-proj --with-geos --with-sqlite3 --with-curl
Step 3: Build and Install GDAL
Once GDAL is configured, you can compile and install it using the following commands:
make
sudo make install
Step 4: Update Shared Library Cache
After the installation, it’s essential to update the shared library cache to ensure the system recognizes the new GDAL version.
sudo ldconfig
Step 5: Verify GDAL Installation
To confirm that GDAL was installed successfully, check the installed version:
gdalinfo --version
You should see the following output (or similar), indicating the installed GDAL version:
GDAL 2.4.0, released 2018/12/14
Step 6: Check 'sf' Package Version in R
Next, you’ll need to check the version of the 'sf' package to ensure it’s compatible with the GDAL version installed. Open R and use the following commands:
installed.packages()["sf", "Version"]
Additionally, ensure that the 'sf' library is installed and loaded:
library(sf)
If the package is not installed, you can install a specific version using remotes::install_version:
remotes::install_version("sf", "1.0.14")
Issue Resolution
In our case, the GDAL version on the server was 2.3.2, which is not compatible with 'sf' package version '1.0.14'. The solution was to update the GDAL version to 2.4.0 using the steps above and then install the required version of 'sf' using:
remotes::install_version("sf", "1.0.14")
This resolved the compatibility issue and allowed successful use of the 'sf' package with GDAL.
Comments
0 comments
Please sign in to leave a comment.