Skip to content

MapServer

Documentation

MapServer has comprehensive documentation that can be found online at https://mapserver.org/.

Key parts of the documentation are:

How MapServer Works

In its most basic form, MapServer is a CGI program that sits inactive on your web server. When a request is sent to MapServer, it uses information from the request URL and the Mapfile to create an image of the requested map.

MapServer overview diagram

Mapfiles

A Mapfile is used to define the data contained in a map and how it will be displayed.

Mapfiles are text files, that contain hierarchical and nested blocks. An annotated Mapfile is displayed below:

# Comment can be added using a hash (#) at the start of a line
# All Mapfiles begin with a MAP block, and finish with a closing END
MAP
    NAME "mymap"

    # the default size used for image output
    SIZE 800 400

    # the projection used for the map
    PROJECTION
        "init=epsg:4326"
    END


    # the extent of the map in the projection
    EXTENT -180 -90 180 90

    LAYER
        NAME "countries" # the name of the layer
        TYPE POLYGON # the layer will display polygons
        STATUS DEFAULT # this means the layer will always be displayed

        # we will use a FlatGeoBuf country dataset
        CONNECTIONTYPE FLATGEOBUF
        DATA "data/naturalearth/ne_110m_admin_0_countries.fgb"

        # we will use a single class for all country polygons
        CLASS
            STYLE
                COLOR 60 179 113 # the colour of the polygons
                OUTLINECOLOR 255 255 255 # the colour of the polygon outline
                WIDTH 1 # the width of the polygon outline
            END
        END
    END
END

Mapfile classes used in the Countries map

MapServer development

The first release of MapServer was in 1997, and is written in a combination of C and C++.

A summary of MapServer development from OpenHub is shown below:

MapServer dependencies

MapServer is built on several image rendering and geospatial C/C++ libraries. The below image shows MapServer's key dependencies:

MapServer dependencies

This means that improvements and features in libraries like GDAL also become available in MapServer. Any GDAL raster driver or vector driver can be used by MapServer.

Interacting with MapServer

Before services like WMS and WFS were added to MapServer, interaction was done using the custom keywords listed on the MapServer CGI Controls page.These are still available for use in MapServer, but this workshop will focus on OGC services. For example we will use the WMS protocol to display the MapServer layer on top of an OSM background using OpenLayers.