MapServer 5.0 with AGG rendering

Previous MapServer versions used GD as the primary raster rendering backend. Because GD is not very capable of high quality output with regards to anti-aliasing, MapServer 5.0 has been released with a new rendering backend.

Anti-Grain Geometry (AGG) is a High Quality Rendering Engine for C++. Key features include rendering of arbitrary polygons with Anti-Aliasing and Subpixel Accuracy.

I’m testing this on Mac OS X 10.4.11 (sorry, no Leopard), and this time we are using MacPorts to install AGG.

$ sudo port install antigraingeometry

This puts AGG in /opt/local.

Now, to enable support for AGG in mapserver, download the MapServer 5.0.0 Source distribution from here and then continue with

$ tar zxvf mapserver-5.0.0.tar.gz
$ cd mapserver-5.0.0
$ ./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 -with-agg=/opt/local/ -with-freetype
$ make

-with-agg=/opt/local/ -with-freetype is the part that is necessary for AGG suport.

The easiest way to test AGG rendering is by using the demo application which has been ported to MapServer 5.0. Download it from here and upack the workshop archive in your apache document root.

Apply this patch to the map file and edit the index.html to match your setup.

This screenshot shows what it looks like (note the antialiasing). Pretty, isn’t it? 😎

Community Mapbuilder

During my research of the current state of the open source GIS community and the viability of the surrounding software, I discovered Community Mapbuilder. It is a powerful AJAX-enabled geographic mapping client that runs in a web browser and supports the Open Geospatial consortium (OGC) standards.

It renders maps from Web Map Services (WMS), so we can integrate it easily with UMN MapServer configured as a WMS server. MapServer is an open source development environment for building spatially-enabled web mapping applications and services.

Using the latest stable Community Mapbuilder 1.0.1 release, I managed to get it running against my MapServer installation on Mac OS X.

btw, to check if your MapServer is built as WMS server, check what mapserv -v reports:

$ ./mapserv40 -v
MapServer version 4.10.3 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=FREETYPE SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER INPUT=EPPL7 INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE

Access SQL Server with Perl DBI

Using the Perl DBI interface, you must first download and install the DBI module (latest version is 1.601). Installing using the cpan command-line tool is the easiest as it will install the dependencies for you.

$ sudo cpan install DBI

Next we are going to build and install FreeTDS. FreeTDS is a set of libraries for Unix and Linux that allows your programs to natively talk to Microsoft SQL Server and Sybase databases. I’m testing this on Mac OS X, so I’m going to install it via MacPorts.

$ sudo port install freetds

Before configuring and installing the DBD::Sybase driver module, make sure that the environment variable SYBASE reflects the path of the FreeTDS installation. MacPorts per default installs FreeTDS in /opt/local.

$ export SYBASE=/opt/local/
$ sudo cpan install DBD::Sybase

To configure FreeTDS to talk to your SQL Server database, edit the configuration file called freedts.conf. In this post, it is located in /opt/local/etc/freetds/freetds.conf.
Finally, here is a simple example to test your installation.

#!/opt/local/bin/perl
use DBI;
my $user = "sa";
my $passwd = "";
my $dbh = DBI->connect( "DBI:Sybase:server=MyServerName",
$user, $passwd, { RaiseError => 1 } )
or die $DBI::errstr;
my $sth = $dbh->prepare("select \@\@servername");
if ( $sth->execute ) {
while ( @dat = $sth->fetchrow ) {
print "servername is @dat\n";
}
}
exit(0);

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.