FOSS Web Mapping Tutorial – part I

In this serie of articles I will show you how to install and configure an open source web mapping solution to make your own Google Maps but based only on open-source and OGC standards (mainly WFS, WMS and SLD).We will try to cover all aspects of the solution, including the data storage, the middleware/application server as well as the web client. We will look at the global solution as a typical 3-tiers solution, very common in web application development:

  • level 1: a data storage, usually a database system but it can be also shapefiles and many other formats,
  • level 2: the application server, delivering web services through a web server,
  • level 3: the web browser or client.

To simplify the process we will install all tiers on the same machine for testing purpose, but you could install the database and application server in different servers, it will not change much (we will consider the different changes later).

We will not talk about GIS but rather web mapping, there are some differences, I will not talk about them in details. Keep in mind that open-source communities are very active in this area and you will be able to have a full GIS package pretty soon I believe.

Talking about Google Maps: yes you will have a similar color scheme but no I will not be able to provide you with the dataset!

What technical solution are we going to use first? I will start with GeoServer (1.4 as of today), a Java-based geospatial server at the heart of this tutorial. In the future I will try to make the same with MapServer.
We will not make a basic installation (such as using the geoserver.exe file for Windows) but rather a more powerful installation that could turn into production later (although not including at this stage replication), which, for me, mean using a J2EE container such as Apache Tomcat (I know it is more a servlet container…), use a spatial database such as PostgreSQL/PostGIS. Finally we will see briefly how to connect Tomcat with Apache Web server to make a complete backend system using the best of each tools.
I will explain every step based on a Mac (most of the steps are similar for Windows and Linux, I will mention if any difference):

  • Part I (this article): intallation of Tomcat, Geoserver, PostgreSQL/PostGIS as well as mapbuilder and openlayers,
  • Part II: setup of a dataset including some basic things to know on spatial data manipulation and connect all tiers together to deliver a final map,
  • Part III: Geospatial server configuration,
  • and finally we will try to identify what’s missing to be production ready.

Install

Tomcat

MacOS X TerminalTomcat is the servlet container in which GeoServer will run. It is a piece of cake to install (whatever platform): for Mac users simply download the zip file of the latest version (as of writing: 5.5.20), unzip it and copy the folder apache-tomcat-5.5.20 into the folder /usr/local/. You can do the unzip and copy of folder with the Terminal if you like it or simply with the Finder (Tips: to access this type of folder not visible by default in the Finder, simply type Apple-key+Shift+G, then type in /user/local and you will see it in your Finder).

Note: for Windows and Linux users you can find .exe file to install it and packages specific to your distribution, so basically in a few click it will be installed in your computer, including a start and stop feature.

Start and Stop Tomcat (MacOS X specific but could be adapted to all platforms)
I do recommend to create 2 files in a directory inside your personal folder (I named it bin/) where you can put 2 files, one named start_tomcat (to…guess what?) and another one stop_tomcat. Here is what you put in this 2 text files (or download them, see below), of course adapt to your configuration (maybe you have a different version of Tomcat…).
start_tomcat:

#!/bin/sh
export CATALINA_HOME=/usr/local/apache-tomcat-5.5.20
export JAVA_HOME=/usr
$CATALINA_HOME/bin/startup.sh

and stop_tomcat:

#!/bin/sh
export CATALINA_HOME=/usr/local/apache-tomcat-5.5.20
export JAVA_HOME=/usr
$CATALINA_HOME/bin/shutdown.sh

You must make these 2 files executable:

chmod ug+x start_tomcat stop_tomcat

Done!…or almost, but definitively the hardest part is done! Anytime you want to start/stop Tomcat, you just have to type in Terminal ./start_tomcat or ./stop_tomcat. By default, Tomcat include a small web server so it can run even without Apache, you can then access Tomcat web interface at http://localhost:8080/ or whatever the name of your machine, but we will see later how to integrate it into Apache web server and start it automatically at boot time.

More on the subject: from Apple Developer Connection, Java and Tomcat on Mac OS X.

Geoserver

Those guys from Geoserver are good with us (not only because they make easy to deploy Geoserver but also because a lot of things in this serie come from discussion with some of them. Thank guys!). They have prepared a geoserver.war file ready to download that make installation similar in al platform. If you know how to download a file, it’s done ;-)

  • make sure Tomcat is shutdown,
  • copy the war file into your Tomcat webapps/ subfolder (on MacOS: /usr/local/apache-tomcat-5.5.20/webapps/),
  • restart Tomcat,
  • access Geoserver web admin at http://localhost:8080/geoserver/ by default (again depending on your configuration)

You can start to play a little bit with Geoserver admin tool and see some examples packaged by default with the application.

Note: Geoserver includes by default mapbuilder (see later for an advance installation) to show some examples with simple dataset. Enjoy it!

PostgreSQL / PostGIS

It’s time now to look at the data storage system. To make something robust, nothing better than a database! But we must choose a RDBMS that can “understantd” our specifity: geospatial elements. In the open-source world you can choose between several RDBMS that can support spatial elements, including the 2 majors:

  • PostgreSQL: often compared with Oracle in terms of features, in our specific area PostgreSQL have a very strong contender: PostGIS, a “plugin” to add geospatial support within PostgreSQL. It is probably the most advance open-source database currently, therefore the one we will choose.
  • MySQL (4.1+ only): support of spatial elements/functions is still in its infancy and lake key elements for us such as coordinate re projection. Although we could use it and it is supported by Geoserver, we do not recommend it for the time being.

You can download PostgreSQL and PostGIS from their respective official websites for Windows and Linux. You should not have any difficulty with this.

Note: starting from PostgreSQL 8, postgreSQL is including postGIS, however it is most of the time an outdated version, therefore we recommend to not install the default version included in postgreSQL but rather the latest one from Refractions.

During postgreSQL installation you can specify whether you allow connection from the outside world (meaning outside the computer where you are installing it). If you install in separate servers the application server and database, make sure to select the box (you can always change it later of course).

For MacOS X I recommend the package made by Kyng Chaos, it includes already PostGIS out of the box and is well integrated with MacOS X (you just need to make sure that you download and install as well 2 of his frameworks GEOS and PROJ that are required for PostGIS).

Installation is a very simple and straight forward process:

  • install first the 2 frameworks GEOS and PROJ,
  • then install the PostgreSQL+PostGIS package and then,
  • if you want to start the database automatically at boot time, install the startupitem package

PgAdmin IIIYou should not have any difficulty for this. It creates a postgres user (with postgres as password) and change access rights to some postgresql folders. The database system is installed in /usr/local/pgsql.

To access the database, you can do it through the Terminal using pgsql command line tool, but you can as well download pgAdmin III (available for all platforms) which can be very convenient too. Finally you can also use phpPgAdmin which is a web interface such as phpMyAdmin for MySQL.

mapbuilder

mapbuilder in EduGISLast but not least: the web client. Mapbuilder community gives you several options to download their software, for the time being we will choose the .war file which will make the installation similar to Geoserver mentioned earlier.

Quick reminder: copy the war file into the webapps/ folder of Tomcat and restart Tomcat, you can now access it at http://localhost:8080/mapbuilder/.

Note: some examples of mapbuilder will connect to the internet to get maps and others will work only if Geoserver is installed as mentioned earlier in this article.

Conclusion

It is about time to end this first article. I know it is frustrating to get everything install and not yet delivering maps! But be patient, in the next article we will connect each pieces together to make it an integrated solution for web mapping, meanwhile it gives you some time to play around and get to know Geoserver and PostgreSQL specially.

Download Zone

my “add-ons” for this article:

One Response to “FOSS Web Mapping Tutorial – part I”

  1. dinger says:

    cool man, can’t wait till part II & III.

Leave a Reply