The goal of this example is to get you up and running with a Mapserver based WMS. We will serve up some source Vector (Shapefiles) and Raster (GeoTIFF) data, and make it available on the web. A working WMS server can feed an OpenLayers? client, amongst many others, making this example a key feature for serving your own data to a wide audience.

Requirements: Working installation of mapserver (with WMS Server and other configurations enabled. see UbuntuBaseStack or AmazonEC2 for examples of getting such a system for yourself). Alternatively you should be able to follow along if you have MS4W on Windows.

1) Make sure we having a web-accessible mapserver cgi

  • If you are running one of the Ubuntu examples, you should have the mapserv executable in /usr/lib/cgi-bin, and Apache 2.0 installed. MS4W has a similar configuration. Open a browser and run:
    #for ubuntu server
    http://server_name_or_ip/cgi-bin/mapserv
    
    #for ubuntu desktop
    http://localhost/cgi-bin/mapserv
    
    #for windows
    http://localhost/cgi-bin/mapserver.exe
    
  • Your browser should display a single line of text saying "No query information to decode. QUERY_STRING is set, but empty." That indicates your mapserver installation is working and ready for use.
  • If running Ubuntu Server, replace server_name_or_ip with the name or ip address of your ubuntu server
  • After replacing the server name appropriately, you now have what we will call your Base Mapserver URI. For the rest of this example, we'll assume it is http://ubuntu_server/cgi-bin/mapserv - you will need to switch your server name (or leave "localhost" as applicable)

2) Get some GIS data

  • Download the World Borders shapefiles to your server. For this example, we'll be putting our data in /usr/local/data
    #make the folder, and make it write-accessible by everyone (a potentially dangerous move)
    sudo mkdir /usr/local/data
    sudo chmod a+rw /usr/local/data  
    cd /usr/local/data
    #get the data
    wget http://mappinghacks.com/data/world_borders.zip
    #uncompress the world_borders.zip
    unzip world_borders.zip
    #delete the original zip file
    rm world_borders.zip
    #get the projection file for the data
    wget http://mappinghacks.com/data/world_borders.prj
    
  • On windows, just download the world_borders.zip and put it in a folder that is readable by all users.

3) get a test mapfile

  • For this example, we'll be placing our mapfiles in /usr/local/maps
    #make the folder, and make it write-accessible by everyone (a potentially dangerous move)
    sudo mkdir /usr/local/maps
    sudo chmod a+rw /usr/local/maps 
    cd /usr/local/maps
    wget http://os.umbrellaconsulting.com/attachment/wiki/UbuntuMapserverExample/test.map?format=raw -O test.map
    

4) Test the WMS server

  • In your browser, go to
    http://ubuntu_server/cgi-bin/mapserv?service=wms&request=getmap&version=1.1.1&layers=world_borders
    
  • You should get back an image!
  • We now have a working WMS server. Neat.

5) Optional: Open up and examine out the mapfile. For this example we'll use nano as our editor, but use whatever editor you like (such as vim on ubuntu).

  • type 'nano test.map' to edit the mapfile - nano is a very basic word processor
    • use arrow keys and page-up/down to move around
    • edit the name of the map if you wish
    • note interesting things, like the WMS metadata on both the map and the world borders layer
    • if you want, change things like the colors of the world_borders layer
    • read up on mapfiles at http://mapserver.gis.umn.edu

Attachments