Skip to content

Instantly share code, notes, and snippets.

@program--
Last active January 21, 2021 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save program--/1e2ad0f5a4d2d6bbca200485b10516a1 to your computer and use it in GitHub Desktop.
Save program--/1e2ad0f5a4d2d6bbca200485b10516a1 to your computer and use it in GitHub Desktop.
Bash script for installing GEOS, PROJ, and GDAL from source on Fedora

Description

This script installs GEOS, PROJ, and GDAL (with Python and NetCDF) from source on Fedora (Only tested with Fedora 33).

The user can specify versions and/or whether to install PROJ datum data with the flags below.

Partially credited to: https://gist.github.com/robinkraft/2a8ee4dd7e9ee9126030

It is generally recommended to install these libraries directly with yum/dnf.

This script should only be used if a specific version is needed.

Usage

  1. Either use curl/wget, or touch install_spatial.sh and copy the contents into it, in your home directory.
  2. Call chmod +x install_spatial.sh to set permissions.
  3. Run script with ./install_spatial.sh [OPTIONS]

NOTE: This script calls sudo rm and sudo rm -rf without the -k flag. Always verify the content of scripts to prevent catastrophic events from occurring.

Options:
    -h, --help          show brief help
    -g, --geos          specify GEOS version
    -p, --proj          specify PROJ version
    -d, --gdal          specify GDAL version
    -s, --projsync      install PROJ datum data? requires PROJ >= 7.0.0
    -k, --keepdata      keep GEOS/PROJ/GDAL temp directories after install?

Examples:
    Install with default versions (GEOS 3.9.0, PROJ 7.2.1, GDAL 3.2.1)
    #> ./install_spatial.sh

    Install with GEOS 3.0.4 instead of 3.9.0
    and PROJ 6.3.1 instead of 7.2.1
    #> ./install_spatial.sh --geos "3.0.4" -p "6.3.1"

    Install and download PROJ datum data
    #> ./install_spatial.sh -s

    Install and keep temp directories
    #> ./install_spatial.sh --keepdata
#!/bin/bash
# Variables
GEOS_VERSION=""
PROJ_VERSION=""
GDAL_VERSION=""
PROJ_DATA='false'
KEEP_DATA='false'
while test $# -gt 0; do
case "$1" in
-h | --help)
echo "Script for installing GEOS, PROJ, and GDAL from source."
echo "Defaults to GEOS 3.9.0, PROJ 7.2.1, and GDAL 3.2.1."
echo " "
echo "Usage: ./install_spatial.sh [OPTIONS]"
echo " "
echo "Options:"
echo " -h, --help show brief help"
echo " -g, --geos specify GEOS version"
echo " -p, --proj specify PROJ version"
echo " -d, --gdal specify GDAL version"
echo " -s, --projsync install PROJ datum data? requires PROJ >= 7.0.0"
echo " -k, --keepdata keep GEOS/PROJ/GDAL temp directories after install?"
echo " "
echo "Examples:"
echo " Install with default versions (GEOS 3.9.0, PROJ 7.2.1, GDAL 3.2.1)"
echo ' #> ./install_spatial.sh'
echo " "
echo " Install with GEOS 3.0.4 instead of 3.9.0"
echo " and PROJ 6.3.1 instead of 7.2.1"
echo ' #> ./install_spatial.sh --geos "3.0.4" -p "6.3.1"'
echo " "
echo " Install and download PROJ datum data"
echo ' #> ./install_spatial.sh -s'
echo " "
echo " Install and keep temp directories"
echo ' #> ./install_spatial.sh --keepdata'
exit 0
;;
-g | --geos)
shift
if test $# -gt 0; then
export GEOS_VERSION=$1
echo "GEOS version $1 specified."
fi
shift
;;
-p | --proj)
shift
if test $# -gt 0; then
export PROJ_VERSION=$1
echo "PROJ version $1 specified."
fi
shift
;;
-d | --gdal)
shift
if test $# -gt 0; then
export GDAL_VERSION=$1
echo "GDAL version $1 specified."
fi
shift
;;
-s | --projsync)
export PROJ_DATA='true'
echo "PROJ_DATA: set to install PROJ datum data."
shift
;;
-k | --keepdata)
export KEEP_DATA='true'
echo "KEEP_DATA: set to keep temp directories."
shift
;;
*)
echo "$1 is not a valid flag."
exit 1
;;
esac
done
if [ "$GEOS_VERSION" = "" ]; then
echo "GEOS version not specified. Defaulting to 3.9.0"
export GEOS_VERSION="3.9.0"
fi
if [ "$PROJ_VERSION" = "" ]; then
echo "PROJ version not specified. Defaulting to 7.2.1"
export PROJ_VERSION="7.2.1"
fi
if [ "$GDAL_VERSION" = "" ]; then
echo "GDAL version not specified. Defaulting to 3.2.1"
export GDAL_VERSION="3.2.1"
fi
bold=$(tput bold)
normal=$(tput sgr0)
#########################
# Start actual script
echo "\n${bold}Installing Dependencies via dnf${normal}\n"
# Dependencies
sudo dnf update
sudo dnf install \
make \
automake \
gcc \
gcc-c++ \
kernel-devel \
@development-tools \
sqlite \
sqlite-devel \
libtiff \
libtiff-devel \
curl \
libcurl-devel \
wget \
bzip2 \
python3 \
python3-devel
echo "\n${bold}Dependencies installed${normal}\n"
# Install GEOS
echo "\n${bold}Installing GEOS${normal}\n"
cd /tmp
wget http://download.osgeo.org/geos/geos-$GEOS_VERSION.tar.bz2
bunzip2 geos.$GEOS_VERSION.tar.bz2
tar -zxvf geos-$GEOS_VERSION.tar
cd geos-$GEOS_VERSION
./configure && make && sudo make install
make check && sudo ldconfig
echo "\n${bold}GEOS Installed${normal}\n"
# Install PROJ
echo "\n${bold}Installing PROJ${normal}\n"
cd /tmp
wget https://download.osgeo.org/proj/proj-$PROJ_VERSION.tar.gz
tar -zxvf proj-$PROJ_VERSION.tar.gz
cd proj-$PROJ_VERSION
./configure && make && sudo make install
make check && sudo ldconfig
if [ "$PROJ_DATA" = true ] ; then
echo "\n${bold}Installing PROJ Data${normal}\n"
sudo projsync --system-directory
fi
echo "\n${bold}PROJ Installed${normal}\n"
# Install GDAL (with python)
echo "\n${bold}Installing GDAL${normal}\n"
cd /tmp
wget https://github.com/OSGeo/gdal/releases/download/v$GDAL_VERSION/gdal-$GDAL_VERSION.tar.gz
tar -zxvf gdal-$GDAL_VERSION.tar.gz
cd gdal-$GDAL_VERSION
CFLAGS="-g -Wall" LDFLAGS="-s" ./configure \
--with-png=internal \
--with-libtiff=internal \
--with-geotiff=internal \
--with-jpeg=internal \
--with-gif=internal \
--with-ecw=no \
--with-expat=yes \
--with-sqlite3=yes \
--with-geos=yes \
--with-python \
--with-libz=internal \
--with-netcdf \
--with-threads=yes \
--with-xerces=yes
make -j2 && sudo make install
make check && sudo ldconfig
echo "\n${bold}GDAL Installed${normal}\n"
if [ "$KEEP_DATA" = false ] ; then
cd /tmp
sudo rm geos-$GEOS_VERSION.tar
sudo rm proj-$PROJ_VERSION.tar.gz
sudo rm gdal-$GDAL_VERSION.tar.gz
sudo rm -rf geos-$GEOS_VERSION
sudo rm -rf proj-$PROJ_VERSION
sudo rm -rf gdal-$GDAL_VERSION
fi
echo "Installations complete:\n"
echo "${bold}GEOS: $(geos-config --version)"
echo "${bold}PROJ: $(proj 2>&1 | head -n 1)"
echo "${bold}GDAL: $(gdalinfo --version)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment