MapServer for ESRI Developers: Getting Started

Posted by Dave Bouwman | Posted in .NET, MapServer | Posted on 09-11-2006

6

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…

Comments (6)

No need to waste time setting up a tile cache, just use Ka-map! Good luck on your adventures in mapserver land.

Cheers,

Dylan

I’ll check out ka-map – I had heard that it was not that stable, but I’ve heard a lot of mis-information on MapServer et al, so I’ll be sure to check it out.

Thanks!

Dear Dave

a couple of comments:

1) about installation: you don’t even need to install Apache if you are in a Windows box, IIS is enough (if you plan to use MapServer with c# mapscript, i see you are .NET oriented)
2) a very nice thing I like about MapServer vs ArcIMS is that you can just copy and paste your asp .net solution (with MapServer dlls under bin) to your web (even shared) hosting and it will work (this meaning that you don’t even need to install MapServer)
3) ka-Map AFAIK is only for php, so maybe is not interesting to you
4) i am sure you can have success with your Tile Caching approach, there is an article about making this with SharpMap (another very good open source web mapping library, specific for .NET), you can easily modify the code for using it with MapServer. The article I am talkin about is here: http://www.codeproject.com/aspnet/sharpmap1.asp and it is from Morten Nielsen, the creator of SharpMap. Maybe I will place an implementation of this for MapServer at my web site in the next time
5) another nice feature about MapServer is that, unlike ArcIMS, generated images can be NOT necessarly be written on disk (to the web output folder), but you can just stream them without phisically writing (ie to a Button Server Control) that is more time-consuming
6) vs AJAX approach, check out the Flash approach (MapServer’s output can be set even to swf Flash file, this is amazing)
7) the best feature MapServer has vs ArcIMS, IMHO is the possibility to serve a wider range of vectorial data, over all PostGIS and Oracle Spatial without SDE

best regards
Paolo

Too bad MapServer isn’t Threadsafe!

http://mapserver.gis.umn.edu/docs/faq/thread_safety

One minor tweak to install/run the demo…

If you just unzip the demo zipfile to same root dir as ms4w,
the demo link is broken; but copying the mapserv-demo directory tree to htdocs allows it to be found.

Probably a better way, by tweaking httpd-conf to look in the apps directory, but will still need to tweak the link.

Egg on my face!
My previous post re: need to copy or tweak to enable demo; after actually reading the install readme, this is explained; just have to restart apache after installing the demo app.

What a pleasant surprise, that the docs actually help!