GDAL and ECW on CentOS 5

Neither of the two popular compression image formats, not Erdas’ ecw nor Lizard Tech’s mrsid are open sourced. Both companies have made significant gestures towards the FOSS community by releasing their code with licenses allowing non-commercial use. However an open source project still cannot distribute libraries which are based on these proprietary SDKs.

A FOSS GIS user, who wants access to ecw compressed imagery has to waltz thru some special steps to get this functionality compiled into his software stack.  The crucial library and toolkit in this stack is GDAL, the “Geospatial Data Abstraction Library” which does the data conversions for many FOSS GIS projects. Once you have GDAL compiled with support for ecw (and/or mrsid) the other GIS software which depends on GDAL will be able to display ecw compressed files.

We’ll outline the steps needed to get support for the popular webmapping server “mapserver” on a CentOS 5 installation.

Dependancies available from yum

First we add from the regular yum repository, and from rpmforge several required binary packages:

proj-4.5.0  (from rpmforge repo)
proj-4.5.0-devel  (from rpmforge repo)
geos-3.1.0
geos-devel-3.1.0
postgis-1.3.2
postgresql-8.1.11
postgresql-server-8.1.11
postgresql-devel-8.1.11
sqlite-3.3.6-2
sqlite-devel-3.3.6
postgresql-pl-8.1.11
gd-2.0.33
gd-devel-2.0.33
php-devel-5.1.6
php-gd-5.1.6
agg-2.5   (use the rpm from rpmforge)
agg-devel-2.5 (again use the rpmforge package)

Source code

Now we download the source packages we’ll need: From the Erdas website download the ECW JPEG2000 Codec SDK Source Code. This requires registering and logging into their site. Next get the source code for GDAL 1.6.0 from OSGeo.  And go to the Mapserver.org site to get the source for mapserver (I used version 5.4.0). Untar/unzip the packages in a directory of your choice.

First compile the ecw library by:

cd libecwj2-3.3
./configure
make
make install

Next change into the gdal source directory, and run

cd ../../gdal-1.6.0/
 ./configure --with-pg=/usr/bin/pg_config --with-ecw=/usr/local --with-sqlite

This compiles GDAL with support for many well know geospatial formats as well as PostGIS spatial layers, ecw, and sqlite (The spatialite project, based on the sqlite database has gained a lot of good publicity lately and is quickly becoming an accepted vector format, so it’s worth getting sqlite compiled in also). Of course, if you’ve got additional libraries, add any other –with-xxx that you need to the configure line.  Now run

make
make install

The default location for the gdal libraries is /usr/local/lib. In order for mapserver to find those libraries I add a file: /etc/ld.so.conf.d/gdal_1.6.0.conf which contains:

cat gdal_1.6.0.conf
/usr/local/lib

Then I run:

ldconfig.

To make sure that the ecw is indeed supported, try:

gdalinfo --formats | grep -i ecw
  ECW (rw): ERMapper Compressed Wavelets
  JP2ECW (rw+): ERMapper JPEG2000

Now go into the mapserver source directory. Here’s my configure line :

./configure --with-geos=/usr/bin/geos-config \
--with-gdal=/usr/local/bin/gdal-config \
--with-ogr=/usr/local/bin/gdal-config \
--with-postgis=/usr/bin/pg_config
--with-agg --with-freetype \
--with-proj=/usr --with-wfs \
--with-gd=/usr \
--with-php=/usr/include/php \
--with-pdf
--with-fribidi-config=/usr/bin/fribidi-config

Notes:

  • –with-fribidi is for Right To Left text labels
  • –withpdf assumes you have installed the pdflib-lite library
  • –with-php compiles mapserver with php-mapscript support
  • –with-proj should point to /usr – NOT a subdir

See the mapserver documentation for more compile options. Then we run

 make

to build the mapserv program (there’s no “make install” step).

Installing Mapserver

Now we simply copy the resulting mapserv executable into apache’s cgi-bin directory, and copy the php_mapscript.so into /usr/lib64/php/modules/ (the system’s php extensions directory defined in /etc/php.ini) and we’re ready to begin creating web maps. The place to start is An Introduction to Mapserver

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>