Skip to content

Instantly share code, notes, and snippets.

@rupestre-campos
Forked from rossoe/gdal_ecw.sh
Created June 15, 2020 20:00
Show Gist options
  • Save rupestre-campos/45a6ede7e455e675f1539408a0f7175d to your computer and use it in GitHub Desktop.
Save rupestre-campos/45a6ede7e455e675f1539408a0f7175d to your computer and use it in GitHub Desktop.
Install GDAL 2.3 with ECW support on Ubuntu 18.04 (working with QGIS 3.6)
#!/bin/bash
##
## Tested on: Ubuntu 18.04 & ECW 5.4 & GDAL 2.3.2 from completely clean install of OS
##
## Download the ERDAS ECW JP2 SDK v5.4 Linux
## https://download.hexagongeospatial.com/downloads/ecw/erdas-ecw-jp2-sdk-v5-4-linux
## Download GDAL v2.3 Source (ex. 2.3.2)
## http://trac.osgeo.org/gdal/wiki/DownloadSource
# Install libpng-dev - otherwise GDAL may compile against internal version of libpng which causes QGIS crashes
sudo apt install libpng-dev
# Add PPA's - 28/02/19 currently only way to avoid QGIS dependency issues when that is installed (line 26)
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
# Setup sources.list & public key
echo "deb https://qgis.org/ubuntugis bionic main" | sudo tee -a /etc/apt/sources.list
wget -O - https://qgis.org/downloads/qgis-2017.gpg.key | gpg --import
gpg --fingerprint CAEB3DC3BDF7FB45
gpg --export --armor CAEB3DC3BDF7FB45 | sudo apt-key add -
sudo apt-get update
# Install QGIS 3.6
sudo apt install aptitude
sudo aptitude -f install qgis python-qgis qgis-plugin-grass
## Unzip ECW libraries and install.
## At the menu, select 1 for "Desktop Read-Only Redistributable"
unzip erdas-ecw-sdk-5.4.0-linux.zip
chmod +x ERDAS_ECWJP2_SDK-5.4.0.bin
./ERDAS_ECWJP2_SDK-5.4.0.bin
## Copy new libraries to system folder
## Rename the newabi library as x64 and move necessary libraries to /usr/local/lib
sudo cp -r ~/hexagon/ERDAS-ECW_JPEG_2000_SDK-5.4.0/Desktop_Read-Only /usr/local/hexagon
sudo rm -r /usr/local/hexagon/lib/x64
sudo mv /usr/local/hexagon/lib/newabi/x64 /usr/local/hexagon/lib/x64
sudo cp /usr/local/hexagon/lib/x64/release/libNCSEcw* /usr/local/lib
sudo ldconfig /usr/local/hexagon
## Build GDAL with ECW support
unzip gdal232.zip
cd gdal-2.3.2
./configure --with-ecw=/usr/local/hexagon
make clean
make
sudo make install
# Set LD_LIBRARY_PATH so that recompiled GDAL is used - will try and replace this with symbolic links in next edit
export LD_LIBRARY_PATH=/usr/local/lib
## Check if it works
gdalinfo --formats | grep ECW
## Remove installation files
sudo rm -rf ~/hexagon/
# Restart
sudo reboot
# You will need to set LD_LIBRARY_PATH after each reboot
export LD_LIBRARY_PATH=/usr/local/lib
echo "SKO BUFFS!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment