Wednesday, November 08, 2006
Posted on Wednesday, November 08, 2006 8:31:19 PM (Mountain Standard Time, UTC-07:00)  Comments [6] | 
Categories: .NET | MapServer

Thought I'd write a series of articles on my forays into the land of MapServer. My goal is pretty simple - I want to get an idea of how difficult it is to create sites based on this platform. Why? Because I'm a consultant, and we are getting more requests from clients to use open source packages. I'm not sure if this is a general trend, or just coincidence, but there have been enough of them to spend some time checking this out .


Getting Started:
One common thing you hear about MapServer is that it's hard to setup. I've installed ArcIMS a couple hundred times since the beta of 3.0, so I've got a good baseline for comparison. So just how difficult is it to set up MapServer?

MapServer Installation Steps:
  1. Download MS4W.
  2. Install it by unzipping it and running the Apache-install.bat file.
  3. Download the Itasca demo (site + data)
  4. Install it by unzipping.
  5. Point a browser at http://localhost:8080, pick the MapServer Demo link at the bottom of the page, and done.


Now, this is not a "killer-app" by any means, but it's on par with a great many "ArcIMS HTML viewer sites". Since the download is the most time consuming part of the installation, assuming you have a good connection, this takes all of 15 minutes. Any complaints about it being to difficult to setup should be put aside.



The only thing I changed is that I'm running Apache on port 8080 so I can still run IIS on port 80. If you want to do this, it is really easy to do - just go into the \ms4w\Apache\conf\httpd.conf file, and change the listen setting to 8080, then re-start Apache.
I was honestly quite suprised by just how smooth this was (what - no servlet engine?!?). Somehow I'd expected the installation to take a couple of postings. Since this went so quickly, I'll try something else...

OpenLayers
For those who have not heard about this, OpenLayers is a client side javascript API for mapping. It's based on Prototype, which makes it compatible with a wide array of fun things like script.aculo.us, and Rico. (follow the links for cross browser Ajaxy goodness). OpenLayers is very simplar to the Google Maps API (it makes a "slippy" or "game-style" map using tiles), but it's open, and you can pull data from a wide array of sources. Of course WMS is one of these options.

I started by downloading OpenLayers and installing it - toughest part of this was opening the tar.gz file - I had to download winrar. Once I could open it, I just dumped the files into the inetpub\wwwroot folder, and opened up the wms example. At this point, I won't get into how simple this is to use. Just click around some examples and look at the source.





Setting up WMS

Since I'm totally new to MapServer, I downloaded the MapServer OGC Web Services Workshop, and installed it (again, simply by unzipping a file). This workshop is a great resource, as it walks you through all the OGC stuff MapServer can handle - capabilities documents, making WFS requests etc etc.

After a little digging, I was able to determine the correct WMS url for one of the demo map services installed by Map Server. To get OpenLayers to pull data from my local map server, all I had to add was two lines of javscript ...
 layer2 = new OpenLayers.Layer.WMS( "Local Map Server", "http://localhost:8080/cgi-bin/mapserv.exe?map=/ms4w/apps/ms_ogc_workshop/service/config.map&service=WMS", {layers: 'land_shallow_topo_2048'} );

map.addLayer(layer2);

And this is not even the most elegant of options, but it worked, and I'm going for speed at this point. Anyhow, the results are shown below.




Again, this is not the least bit earth shattering, and it's a loooong way from a production application or an in-depth understanding, but the total time investment thus far (including this write up) has been a little over one hour. Thus, I think it's safe to say that the basic learning curve here is now in the realm of reasonable. Will your manager set this up? No. But this is no more complex (and may be simpler) than setting up ArcIMS or ArcGIS Server.

Next Steps

Data:
I guess the next thing would be to use some data of my own. I hear that MapServer can pull vector data from ArcSDE 9.1, so I'll start there.

Cartography:
Then I'll want to see how hard it is to create a good looking map - no offence, but many MapServer powered sites look like the cartography was done by pre-schoolers. Maybe there are some tools to ease the pain.

Tile Caching:
Another idea I have (and I may tackle this sooner rather than later because it's interesting) is to create a tile cache using an ASP.NET HTTP handler. Basically the handler would sit in front of MapServer, and when a request came in from OpenLayers, it would check it's cache first, and if the tile did not exist on disk, it would call MapServer to create the image, which it would then add to the cache after sending to the client. There are two nice things about this model: 1) you only create and store tiles that are actually used, and 2) the more the site is used the faster it gets (until all tiles are cached!) I'll be keeping an eye on the OSGeo "tile spec" as this will likely prove to be a useful model.

Once I get this stuff working, I'll start paying more attention to the front end - see what I can leverage in OpenLayers in terms of identifying features, and pulling the feature info from MapServer's WFS, or sending the request to an ASP.NET RESTful service which then hits MapServer and maybe a little NetTopologySuite to do some analysis. Who knows...