Technical Overview: UMN MapServer

MapServer is an open source package to create internet-based mapping applications. It is popular with developers who wish to create their own geospatial servers instead of depending on third party servers such as Google Maps or Microsoft Virtual Earth.

Originally developed by the University of Minnesota with the assistance of NASA, MapServer is currently managed by the Open Open Source Geospatial Foundation (OSGeo). This was established to include MapServer and related open source GIS projects. MapServer continues to be often referred to as “UMN MapServer” to distinguish it from commercial “map server” products.

MapServer can work with both raster data and vector data. In the most basic configuration, MapServer creates a raster image which is embedded in a HTML file. This tends to be cumbersome to use, so it is more usual to use MapServer through one of the MapScript programming interfaces. The most efficient way to use MapServer is to use it as a WMS server, serving tiles to client software (eg. OpenLayers) in an AJAX fashion.

MapServer supports the concept of layers. Each layer is defined using a map file. This is a text file that includes configuration information for the layer. For example, here is the map file for the ASTER (satellite image) raster layer for the EcoMap Costa Rica project:

# Sample Raster Image
# ASTER satellite tile for http://www.ecomapcostarica.com
NAME "Aster"
UNITS DD
EXTENT -180.00 0.00 -60.00 90.00
SIZE 640 480
IMAGECOLOR 189 202 222
TRANSPARENT on
IMAGETYPE my_png
SHAPEPATH "/myhome/mapdata/shp/"
FONTSET "/myhome/fonts/fontset.txt"
CONFIG "PROJ_LIB" "/myhome/local/share/proj/"
DEBUG on
STATUS ON

OUTPUTFORMAT
  NAME my_png
  DRIVER "GDAL/PNG"
  MIMETYPE "image/png"
  IMAGEMODE RGBA
  EXTENSION "png"
END

##################################### 
# Web object
#
WEB
     IMAGEPATH "/mywebdir/cr/map/tmp/"
     IMAGEURL "/map/tmp/"
     METADATA
       "wms_title"     "ASTER Image Server"
       "wms_onlineresource" "http://www.ecomapcostarica.com/map/mapserv.cgi?map=/myhome/cr_aster.map"
       "wms_srs"       "EPSG:4326"
     END
     LOG "/myhome/mapdata/mapserv.log"
END

PROJECTION
  "init=epsg:4326"
END

##################################### 
# Raster Layer
#
LAYER
     NAME "aster"
     METADATA
       "wms_title"   "aster"
     END
     DATA "si_tiled.tif"
     PROJECTION
        "init=epsg:4326"
     END
     STATUS default
     TYPE raster
     MAXSCALE 1000000
END
END # mapfile

This is configured to produce WMS tiles. The image source and projection (EPSG:4326) are provided. Most of the other settings (eg. the font file) are defaults that are not required in this example. The image is defined in a TIFF raster. It is not apparent from the map file, but the TIFF image has been tiled and includes a tile index for efficiency.

Here is a more sophisticated example that provides the “synthetic stream” (theoretical river positions) data for the EcoMap Costa Rica maps:

# Synthetic Stream example MapScript file
NAME "Stream"
UNITS DD
EXTENT -180.00 0.00 -60.00 90.00
SIZE 640 480
IMAGECOLOR 189 202 222
TRANSPARENT on
IMAGETYPE png
# Change this path to the local SHP data path on your server
SHAPEPATH "/your/shape/directory/"
# We do not use fonts in this example: change this path, if you do
FONTSET "/your/config/directory/fonts/fontset.txt"
# You may need to change this path if you are on a shared system or if proj
# is installed in a non-standard place
CONFIG "PROJ_LIB" "/local/share/proj/"
STATUS ON

#####################################
# Symbol for drawing thick lines
# To draw thick lines, we have to draw the line using a symbol
# We shall use this at high zoom levels
SYMBOL
     NAME "BigLine"
     TYPE ELLIPSE
     POINTS 1 1 END
END

#####################################
# Web object
# This is where we configure MapServer to use WMS
#
WEB
# not used. Should point to a tmp directory on your webserver
     IMAGEPATH "/your/web/directory/tmp/"
# not used - the URL directory equivalent of IMAGEPATH
     IMAGEURL "/map/tmp/"
# WMS MetaDATA 
     METADATA
# Name of the WMS Server
       "wms_title"     "WMS Demo Server"
# Full URL to this WMS resource
# This is the same URL that is passed to OpenLayers in the above HTML
       "wms_onlineresource" " http://www.your-domain.com/mapserv.cgi?map=stream.map "
# This specifies the project and geoid to use. EPSG:4326 corresponds to WGS-84
# We use WGS-84 throughout these examples. It is handy and Virtual Earth uses it.
# MapServer could re-project the data, if necessary
       "wms_srs"       "EPSG:4326"
     END
END

# This the projection that this map file uses
PROJECTION
  "init=epsg:4326"
END

#####################################
# We have two layers. Both are called 'streams' but have limited zoom ranges.
# This is the 'polylines' version which appears when zoomed out
# Note that the stream data is quite complex, so we hide the streams completely when
# zoomed out too far (greater than 1:400000)
LAYER
     NAME "streams"
# Layer name for WMS
     METADATA
       "wms_title"   "Streams"
     END
# This is our data source. It is a shape file (cr_synth_stream.shp) in the
# shape path that is defined above.
# The data is already in the WGS-84 (EPSG:4326) geoid & projection.
     DATA "cr_synth_stream"
     PROJECTION
        "init=epsg:4326"
     END
     STATUS default
     TYPE line
     LABELCACHE off
# Scale Range
     MAXSCALE 400000
     MINSCALE 25000
# Draw the layer as a blue-cyan line
     CLASS
          STYLE
               SIZE 1
               COLOR 0 192 255
          END
     END
END


#####################################
# This layer is as above, but draws a thick polyline and
# only appears when zoomed in more than 1:25000
LAYER
     NAME "streams2"
     METADATA
       "wms_title"   "Streams"
     END
     DATA "cr_synth_stream"
     PROJECTION
        "init=epsg:4326"
     END
     STATUS default
     TYPE line
     LABELCACHE off
# Only define max scale where the thin version takes over
     MAXSCALE 25000
# Draw the layer as a thick blue-cyan line using the BigLine symbol (defined above)
     CLASS
          STYLE
               SIZE 2
               COLOR 0 192 255
               SYMBOL "BigLine"
          END
     END
END

# end of this map file
END

This example plots a shape file of lines. This file is defined in native ESRI SHP format. The file consists of two sub-layers, defined by LAYER objects. These plot the same data, but set the line thickness according to the scale level.

Here is an example screenshot of the final application, showing the ASTER imagery around Arenal Volcano and La Fortuna in Costa Rica:

Sample UMN MapServer application.

The scale bar and other controls are provided by Open Layers. Other layers such as field data have been switched off for clarity.

MapServer also supports feature queries, with the results being returned in the image layer or as a text list. Queries can be according to attributes and/or geography.

As can be seen, MapServer is a very powerful software package. Unlike third party map services, MapServer maps can be easily customized for the application at hand. Of course this takes more time to set up. Also, unlike services such as Google Maps and Microsoft Virtual Earth, the application developer has to provide the map data. A final disadvantage is that MapServer requires a certain level of skill to install. Typically it will have to be built on the web server in question. This is not a major task for a professional programmer or for someone who has built their own Apache installation, but it is beyond typical HTML / JavaScript beginners who may find third party systems much easier to use.

MapServer can be downloaded from the main MapServer website at http://mapserver.org. This site also includes documentation, FAQs, and other resources.

MapServer was chosen for the EcoMap Costa Rica project because services such as Google Maps and Microsoft Virtual Earth had very poor map coverage of rural Costa Rica. A developer may also choose to use MapServer if they do not want to be tied to the whims of a third party system; or for commercial reasons (both Google and Microsoft charge for most commercial implementations). Finally, the appearance of a MapServer map can be readily changed. This is difficult or impossible with a third party service.

Leave a Reply