All posts by Dirk Raffel

Dirk is a freelance senior software consultant/engineer/architect located in Berlin, Germany. His key expertise includes embedded and system programming in areas of public transport, railway technology, automotive/traffic telematics. Read more...

Include EPS files in LaTeX

Recently I wanted to include a directed graph in a LaTeX document. I was running dot on the graph file

$ dot -Tps2 nfa.dot > nfa.eps

to receive the EPS file which I wanted to include in LaTeX. Running TeXShop with pdflatex for typesetting on a file containing

\begin{figure}[!htb]
\centering
\includegraphics[scale=.7]{nfa.eps}
\caption{Digraph.}
\label{fig:digraph}
\end{figure}

however returns the error

! LaTeX Error: Unknown graphics extension: .eps.

This can be resolved by adding

\usepackage{epstopdf}

which allows to convert eps images to pdf for use with pdflatex. This works perfect. 😎

Building MapServer 4.10.3 with Java Mapscript on Mac OS X 10.4.10

UMN MapServer with the well-known Itasca application, running as a CGI application, under Apache2 on Mac OS X

MapServer

This is a detailed description about how to build and install MapServer and all (well, most) supporting libraries on Mac OS X. It’s all open source and freely available for download, and we are going to use the latest versions available.

Note that I’m a beginner with MapServer, so I’m not yet proficient in all the configuration options. Thus we are going to create a basic MapServer environment first, where I’m basically interested in using Java MapScript within a J2EE Web environment. However, after becoming hopefully more familiar with MapServer, it’s likely that I’ll try to rebuild it with additional support for other options.

expat
expat is an XML parser library written in C. Get expat-2.0.1.tar.gz from http://expat.sourceforge.net/

$ tar zxf expat-2.0.1.tar.gz
$ cd expat-2.0.1
$ ./configure --mandir=/usr/local/share/man CFLAGS=-O2
$ make
$ sudo make install

libgif
libungif is a library for reading and writing gif images. Get giflib-4.1.4.tar.gz from http://sourceforge.net/projects/libungif

$ tar zxf giflib-4.1.4.tar.gz
$ cd giflib-4.1.4
$ ./configure --mandir=/usr/local/share/man CFLAGS=-O2
$ make
$ sudo make install

libjpeg
libjpeg can be found on http://www.ijg.org/. Installing goes like this (see here)

$ wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
$ tar zxf jpegsrc.v6b.tar.gz
$ cd jpeg-6b
$ cp /usr/share/libtool/config.sub .
$ cp /usr/share/libtool/config.guess .
$ ./configure --enable-shared --enable-static
$ make
$ sudo make install
$ sudo ranlib /usr/local/lib/libjpeg.a

libpng
libpng is the official PNG reference library. Get libpng-1.2.18.tar.gz from http://www.libpng.org/pub/png/libpng.html.

$ tar zxf libpng-1.2.18.tar.gz
$ cd libpng-1.2.18
$ ./configure --mandir=/usr/local/share/man CFLAGS=-O2
$ make
$ sudo make install

libtiff
libtiff is a library for reading and writing TIFF images. Get tiff-3.8.2.tar.gz from http://www.libtiff.org/

$ tar zxf tiff-3.8.2.tar.gz
$ cd tiff-3.8.2
$ ./configure --mandir=/usr/local/share/man CFLAGS=-O2
$ make
$ sudo make install

libGD
GD is an open source code library for the dynamic creation of images by programmers. Compiling instructions on Mac OS X can be found here.

$ wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
$ tar zxf gd-2.0.35.tar.gz
$ cd gd-2.0.35

Assuming you have the Apple X11 SDK installed, link fontconfig header files where GD can find them:

$ sudo ln -s /usr/X11R6/include/fontconfig /usr/local/include
$ ln -s `which glibtool` ./libtool
$ ./configure
$ make
$ sudo make install

Additionally you might run some GD Tests now if you like.

PROJ.4
PROJ.4 is a Cartographic Projections library.

$ wget ftp://ftp.remotesensing.org/proj/proj-4.5.0.tar.gz
$ tar zxf proj-4.5.0.tar.gz
$ ./configure –mandir=/usr/local/share/man CFLAGS=-O2
$ make
$ sudo make install

Note: You might need to unzip the proj-datumshift file for useful datums for the U.S., Canada and New Zealand. See here. I haven’t tested it though.

libGeoTIFF
GeoTIFF is a library for reading, and writing GeoTIFF information tags.

$ wget ftp://ftp.remotesensing.org/pub/geotiff/libgeotiff/libgeotiff-1.2.4.tar.gz
$ tar zxf libgeotiff-1.2.4.tar.gz
$ cd libgeotiff-1.2.4

The GCC compiler on Mac OS X 10.4.10 (Darwin) does not understand the -shared option, so we have to provide a patch.

Get this and this and apply these patches. Then

$ ./configure --mandir=/usr/local/share/man --with-libtiff=/usr/local --with-jpeg=/usr/local --with-zip=/usr --with-proj=/usr/local
$ make
$ sudo make install

btw, you should ignore the warnings /usr/bin/ld: warning -L: directory name (/lib) does not exist 😉

GEOS
GEOS (Geometry Engine – Open Source) is a C++ port of the Java Topology Suite (JTS). Make sure that you have a SWIG version >= 1.3.28.

$ wget http://geos.refractions.net/geos-3.0.0rc4.tar.bz2
$ tar jxf geos-3.0.0rc4.tar.bz2
$ cd geos-3.0.0rc4
$ make
$ sudo make install-strip

GDAL
The Geospatial Data Abstraction Library is a translator library for raster geospatial data formats that is released under an X/MIT style Open Source license by the Open Source Geospatial Foundation.

$ wget http://download.osgeo.org/gdal/gdal-1.4.2.tar.gz
$ tar zxf gdal-1.4.2.tar.gz
$ cd gdal-1.4.2
$ ./configure --mandir=/usr/local/share/man --without-python --with-threads --with-static-proj4=/usr/local --with-libtiff=/usr/local --with-geotiff=/usr/local --with-jpeg=/usr/local --with-gif=/usr/local --with-png=/usr/local
$ make
$ sudo make install

MapServer
MapServer is an Open Source development environment for building spatially-enabled internet applications. The current release, as of this writing, is 5.0.0. However, the MapServer 4.10 to 5.0 Migration Guide indicates some changes that must be made to MapServer applications when migrating from version 4.10.x (or earlier versions) to 5.x (i.e. backwards incompatibilities). We are going to use a demo application for MapServer 4.x that has not been upgraded for version 5.x yet, so for now we’ll install the latest 4.10.3 release. If I have some time later I’ll give the new 5.x release a try…

$ wget http://download.osgeo.org/mapserver/mapserver-4.10.3.tar.gz
$ tar zxf mapserver-4.10.3.tar.gz
$ cd mapserver-4.10.3

First we have to apply this patch for mapscript/java/Makefile.in. Then continue with

$ ./configure --mandir=/usr/local/share/man --with-proj=/usr/local --with-gdal=/usr/local/bin/gdal-config --with-ogr --with-gd=/usr/local --with-xpm=/usr/X11R6 --with-wfs --with-wcs --with-wfsclient --with-wmsclient
$ make
$ cd mapscript/java
$ make interface
$ make

Apache2
We’ll install Apache2 via fink. fink is a package management system that aims to bring the full world of GNU and other common Open Source software to Darwin and Mac OS X. It is based on Debian Linux’s apt-get system. Download it first at http://fink.sourceforge.net/

Before installing Apache2 you may want to update fink first:

sudo fink self-update

This command automates the process of upgrading to a new fink release.

Then install Apache2 with the command

sudo fink install apache2

Note that fink will prompt you with the list of dependant packages that will be installed, simply press enter to accept.

To actually enable a module for Apache2, it is necessary to create a symlink in the directory /sw/etc/apache2/mods-enabled to the .load (and .conf, if it exists) files associated with the module in mods-available/. To load the cgi module: cgi.load -> /etc/apache2/mods-available/cgi.load. cgi scripts go in the directory /sw/lib/cgi-bin.

When it’s done, you’ll be able to start Apache2 by executing:

/sw/sbin/apachectl start

Run MapServer as a CGI application
First download the demo application for MapServer 4.x. The apache document root is /sw/var/www, so unpack the workshop archive in this directory.

Lastly, we have to edit index.html to reflect our configuration. There are HTML comments marking the sections that need to be changed:

<input type="hidden" name="map" value="/sw/var/www/workshop/itasca.map">
<input type="hidden" name="program" value="/cgi-bin/mapserv40">
<input type="hidden" name="root" value="/workshop">
<input type="hidden" name="map_web_imagepath" value="/sw/var/www/tmp/">
<input type="hidden" name="map_web_imageurl" value="/tmp/">

In my next post, I’m going to look at embedding Java MapScript in a J2EE web application.