ECW Images With GDAL On Ubuntu 14.04


I recently ran into some issues at work with building some new Mapserver servers we’re building. Using an UbuntuGIS repo we had a perfect Mapserver and GDAL build for 99% of the products we deliver on a day-to-day basis (with greater reliability than our old system) however it GDAL doesn’t handle the proprietary ECW format out of the box. It can be brought in but there is some strict licensing terms and we didn’t want to risk running afoul of them, nor did we want to have to run the arbitrary, closed source blobs in the current ECW SDK version. Thankfully the version 3.3 SDK is open source if you can source it.


Updated 2017-04-04 to avoid issues created by updated versions of libraries.

First if you haven’t done so, let’s add the ubuntugis-unstable repository and install all the needed packages:

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update && sudo apt-get install g++ gcc gdal-bin=1.10.1+dfsg-5ubuntu1 libgdal1h=1.10.1+dfsg-5ubuntu1 libspatialite5=4.1.1-5ubuntu1 libgdal-dev=1.10.1+dfsg-5ubuntu1 libgeos-dev=3.4.2-4ubuntu1 libspatialite-dev=4.1.1-5ubuntu1 make unzip wget
sudo apt-mark hold libgdal1h libspatialite5 gdal-bin libgdal-dev libgeos-dev libspatialite-dev

The only annoying thing here is libgdal-dev is required to build the ECW plugin once the ECW driver is installed and it requires a bunch of extra packages.

Next up we need to grab the script to build in ECW support for GDAL; unfortunately the UbuntuGIS team has so far only made it available for Raring Ringtail (13.04) and rather than risking using that package repository and running into conflicts, we can just wget the right package from Launchpad and extract the single script we need.

mkdir ~/ecwtemp && cd ~/ecwtemp
ar vx libgdal-ecw-src_1.10.0-1~precise4_all.deb
tar -xzf data.tar.gz
sudo cp usr/src/libgdal-ecw-1.10.0.tar.gz /usr/src/
sudo cp usr/bin/gdal-ecw-build /usr/bin/

With that out the way we can pull down the code for 3.3 version of the ECW SDK which is still open source. I’ve re-uploaded it to an Amazon S3 bucket so we can download it over HTTPS, however if it isn’t available you can download the original from here.

Please note: I have not examined the code in this .zip for vulnerabilities or malware yet, I’m relying on the honesty of the guy who uploaded it for his Ubuntu 13.04 tutorial and other people who suggested it (1, 2). I cannot guarantee the safety of the code at this current time, use at your own risk. It’s worked fine for us so far.

cd libecwj2-3.3
sudo make install

Sweet, with that out the way let’s build ECW support into GDAL! When doing this we’ll run into the little problem that the gdal-ecw-build command expects GDAL 1.10 which was provided with the Raring Ringtail UbuntuGIS repo, but we can create a folder for the 1.11 version, copy it over and it will still work.

sudo gdal-ecw-build /usr/local
sudo mkdir /usr/lib/gdalplugins/1.11
cd /usr/lib/gdalplugins/1.10
sudo cp /usr/lib/gdalplugins/1.11
sudo ldconfig

That should be all done, to confirm that GDAL has ECW support run gdalinfo --formats | grep -i "ecw" and you should get the following output:

vagrant@ecw:~$ gdalinfo --formats | grep -i "ecw"
  ECW (rw): ERDAS Compressed Wavelets (SDK 3.x)
  JP2ECW (rw+v): ERDAS JPEG2000 (SDK 3.x)