Configure MapServer to be a WMS or WFS Server

Through the mapfile (.map) configuration files MapServer can be configured to act as a Web Map Service [WMS], Web Feature Service [WFS] (read only non transactional) or a combination of both in one file.  This topic aims to outline some of the principals associated for use in the UK with iShare but it should be noted that there are more advanced options available from the MapServer website www.mapserver.org.

If the .MAP file is associated with a Mapsource in your iShare installation then you can make use of the getows end point. The URL for the WMS or WFS would be one of the following respectively:

http://name.of.server/ishare.web/getows.ashx?mapsource=Client/AllMaps&service=WMS&request=GetCapabilities

http://name.of.server/ishare.web/getows.ashx?mapsource=Client/AllMaps&service=WFS&request=GetCapabilities

where Client/AllMaps is your mapsource.

If a WFS request made to GetOWS.ashx has a filter, then it will have a limit of 10000 results by default. The limit can be changed in individual requests by adding a MAXFEATURES=x parameter to the request (where x is the desired maximum number of results to return).

.MAP Configuration

WMS and WFS require a NAME and PROJECTION to be defined – British National Grid is epsg:27700 (WGS84 is 4326).

A series of METADATA tags need to be defined in the . map file, together with WEB and LAYER levels to enable this functionality.  As the WMS and WFS are both OGC web services the generic tags can often be substituted (i.e.  wms_title can be used as ows_title). Each layer should have a CLASS that has a name.

See the entries in the Example WMS code below:

Example WMS Code
MAP
   EXTENT 480000 149000 504600 169000 # Tile Cache
   FONTSET "D:/mapserver/shared/fonts/fonts.list"
   TEMPLATEPATTERN "."
   SYMBOLSET "D:/mapserver/shared/symbols/symbols.sym"
   SHAPEPATH "D:/Maps/Workshop/"
   SIZE 512 512
   MAXSIZE 8192
   STATUS ON
   UNITS METERS
   NAME "Astun Technology WorkShop"
   IMAGETYPE AGG_PNG
   OUTPUTFORMAT
	NAME "AGG_PNG"
	DRIVER "AGG/PNG"
	MIMETYPE "image/png"
	IMAGEMODE RGBA
	TRANSPARENT ON
	EXTENSION "png"
   END
   CONFIG "PROJ_LIB" "D:\mapserver\cgi-bin5.4\proj\nad"
   PROJECTION
      "init=epsg:27700"
   END
   WEB
      METADATA
         ows_title "Astun Technology Workshop WMS Server example"    
  		 ows_enable_request "*"
         ows_srs "EPSG:27700"  ## Recommended
         ows_abstract "This is an example WFS server from MapServer"
      END
      LOG "D:\mapserver\tmp\ms.log"
   END
   LAYER
      NAME "Wards"
      STATUS OFF
      TYPE POLYGON
      UNITS METERS
      DATA "Overlays/Council/Wards"
      METADATA
         ows_title "Ward boundaries"
         ows_abstract "Ward boundaries derived from OS OpenData"
         wms_extent "480000 149000 504600 169000" ## can use the map level extent values
      END
      TEMPLATE "blank.html"
      CLASS
         NAME ""
         STYLE
            OUTLINECOLOR 0 0 255
            WIDTH 4
         END
      END
   END
END


For a WFS Server there are some additional entries that are required e.g.
  • gml_featureid - for the features to have a unique key
  • gml_include_items – for which fields to return – this can be a comma separated list of field names or simply all as shown in Example WFS Code below.
  • DUMP TRUE – ensures that the feature data is returned


Example WFS Code
MAP
   EXTENT 480000 149000 504600 169000 # Tile Cache
   FONTSET "D:/mapserver/shared/fonts/fonts.list"
   TEMPLATEPATTERN "."
   SYMBOLSET "D:/mapserver/shared/symbols/symbols.sym"
   SHAPEPATH "D:/Maps/Workshop/"
   STATUS ON
   UNITS METERS
   CONFIG MS_ERRORFILE "D:/mapserver/tmp/debug.log"
   NAME "Astun Technology WorkShop WFS example"
   CONFIG "PROJ_LIB" "D:\mapserver\cgi-bin5.4\proj\nad"
   PROJECTION
      "init=epsg:27700"
   END
   WEB
      METADATA
         ows_title    "Workshop WFS Server example"    
         ows_srs      "EPSG:27700"  ## Recommended
         ows_abstract "This is an example WFS server from MapServer"
  		 ows_enable_request "*"
      END
      IMAGEPATH "D:\mapserver\tmp\"
      IMAGEURL ""
      LOG "D:\mapserver\tmp\ms.log"
      TEMPLATE "globexml.xml"
   END
  ## Overlays Start Here ##
   LAYER
      NAME wards
      STATUS ON
      TYPE POLYGON
      DATA "Overlays/Council/Wards"
      METADATA
         ows_title    "Ward boundaries" ## REQUIRED
         ows_abstract "Ward used in the workshop derived from OS OpenData"
         gml_featureid "NUMBER" ## REQUIRED
         gml_include_items "all"  ## Optional (serves all attributes for layer)
      END
      DUMP TRUE #Required if using Mapserver 5.x or below
      CLASS
      END
   END
END

Client GIS Connection Examples


We have included some sample Client GIS Connection examples for both WMS and WFS e.g.