Web Map Services
Overview
We've been using WMS for interacting with MapServer for Mapfile examples. In this exercise we'll look in more detail at how to configure WMS services in MapServer.
The MapServer WMS documentation is available here.
METADATA Blocks
Web services are configured using METADATA blocks. These are key-value pairs, for example: "wms_title" "My WMS Services".
Tip
It is good practice to put the key names in quotes. This is not required, but it makes it clearer that they are strings and not Mapfile keywords. Keys can also contain strings such as field names, which could contain spaces. Without quotes these will cause syntax errors in the Mapfile.
Prefixes are used to configure different types of web service. For example:
wms_is used for WMS services, for example"wms_title"can be set in theWEBMETADATAblock to set the title of the WMS service. This will be seen when read with client applications such as QGIS.wfs_is used for Web Feature Services.oga_is used for the new OGC API - Features.
Tip
If settings are to be used for multiple services, then rather than duplicating values for wms_, wfs_ etc. you can use the ows_ prefix and these settings will apply to all open web services. You can still override this top-level setting for individual service types if needed.
WMS Request Types
There are several different types of WMS request.
GetMap- for returning map imagesGetLegendGraphicfor returning legend imagesGetCapabilitiesfor returning XML metadata of the WMSGetFeatureInfo- for returning feature attributes at a query locationDescribeLayer- returns an XML description of the WMS layer(s)
More details are in the documentation.
GetLegendGraphic
A sample request for the legend for the polygons.map is as follows:
Tip
The names applied to the legends are based on the CLASS NAME in the Mapfile. If this is not set then no legend image is created for that layer.
Exercises
- If you've read this far you deserve to discover one of MapServer's Easter eggs. Try changing the output format to
&format=image/txt. We'll use thepolygons.mapfor the request: http://localhost:7000/?map=/etc/mapserver/polygons.map&service=wms&version=1.3.0&request=GetMap&layers=buildings&format=image/txt - Create a
GetLegendGraphicrequest, but for thepoints.mapfor thelayer=poi. - Run a GetCapabilities request for the
polygon.map. Add variousMETADATApairs listed in the Web Object Metadata and check its output in theGetCapabilitiesresponse.