Get Over the First Hump In Making Completely Custom, Beautiful Maps: Install Mapnik on Ubuntu

By Tom MacWright on Dec 18 2008 . Posted in MapBox.

As many of you read earlier on this blog, we released Nice Map as a bridge for Drupal to better communicate with WMS servers. Jeff gave a nod to NASA’s free server, which is a great source for beautiful surface imagery and an easy way to test WMS clients. However, the real benefit of mapping with WMS is that you can drop in any WMS-compliant server you like, and Nice Map and other clients will do the legwork of getting beautiful maps on your site. This opens up the possibility for completely custom, beautiful maps like we have on Stumble Safely – maps that can set your site apart from the masses of Google Maps and match the zaniest color schemes. The level of flexibility offered by the WMS protocol and servers is an incredible boon for anyone doing online maps. Here’s one example of a custom map we built with this.

Luckily, there’s an open-source project, Mapnik that makes building a WMS server into a matter of assembly rather than one of guesswork. In its earlier iterations, Mapnik gained a reputation for being a pain to install, but with the changes in 0.5 and up, it has become quite straightforward – dare I say, in some cases, easy. There are plenty of options for installing it: fastcgi, wsgi, TileCache, SVN or the packaged release, etc.

But if you’re using Mapnik in order to get a great WMS server, it’s nice to have an option with batteries included_: this method puts all of the ingredients together: Mapnik, lxml support for speed, PostGIS compatibility, patches for a few common issues, and a modpython server so that you can run it all on Apache.

First, I’ll go over the basic server requirements for this solution. Put simply, it’s great for Debian or Ubuntu systems on dedicated or virtual private servers. There are installation instructions for Windows and Macintosh on Mapnik.org, but if you’re setting up a web server, Ubuntu is a great choice, and hosting companies like Slicehost are making virtual private servers inexpensive, fast, and incredibly flexible. You’ll need about 140MB to build and install Mapnik if you don’t already have any of the required libraries and tools – in a fresh, minimal Ubuntu install, apt-get brings the installed packages to 123MB.

So assuming that you’ve got an Ubuntu server where you can use “sudo” to do operations with root privileges, installing Mapnik is mostly a snap. I’ll go over the quick method first.

  1. Get mapnik_matic by checking it out from our repository
    svn co https://svn3.cvsdude.com/devseed/sandbox/mapnik_matic/
  2. Run the installation shell script with admin privileges*

    • In Ubuntu 7.x,
      sudo ./mapnik.sh
    • In Ubuntu 8.x,
      sudo ./mapnik_8.sh
  3. Edit map.xml, changing the path /home/tom/mapnik_matic/GIS/ to the path to your GIS directory
  4. Set up Apache according to the file sample_apache_config.dev. If you’re using virtual hosts, you can simply edit the paths indicated in the file, copy it into sites-available, and linking this file to sites-enabled.
  5. Restart Apache and try it out.
  • Note: This step, which includes compiling Mapnik from source, can take a very long time on SliceHost servers.

Here’s an example WMS request:


http://yourserver.com/wms.py?width=520&height=260&styles=Plain&bgcolor=0xa0acb8&request=GetMap&version=1.1.1&format=image/png&layers=world&srs=EPSG:3395&EXCEPTIONS=application/vnd.ogc.se_inimage&bbox=-179,-58.8110470437,179,72.092336216

If you get a rendered image, rejoice! Your WMS server is ready to go and ready to hook up to great clients like Nice Map and qgis.

Stay tuned for details on how to get Mapnik jiving with PostGIS!

A big thanks to Troy at New America Foundation, a long time Drupal user who financed some of our initial work with Mapnik. Please get in touch with us if you are doing cool things with Mapnik and have some functionality that you think we should know about. And please post patches to Nice Map.

0 tweets link to this blog post. Start a conversation with @developmentseed on Twitter.

Search

No results found.
About
Projects
Team
Blog