Creating an OGC Web Feature Service
Using MapServer and PostGIS

Enabling GeoJSON output

The default output format for WFS, and the only one currently demanded to be supported by the OGC standard, is GML. However, developers of modern web applications tend to move away from the traditional XML-based interfaces and turning more and more to the use of REST-based APIs that use more simple and light-weight exchange formats. For use in web-clients, JSON is a logical choice, and thus GeoJSON for spatial data.

Therefore, most server software is supporting JSON and GeoJSON, and MapServer is no exception. You just have to set the behaviour of your service by making the appropriate additions to your .map file.

Edit the configWFS.map file by adding the sections highlisted in Listing 1 below. Do not forget to exchange the [NETPATH] parameters with its proper value...

In lines 7–13 you tell MapServer to use the GeoJSON output driver that is available in the OGR library. The MIMETYPE parameter is the standardised (by the W3C) naming you'll have to use in the URL request. In 22 you add the format to the list of available formats that this instance will deliver (adding it to the default list which already includes the GML formats).

Testing GeoJSON output

You can test the geoJSON output simply by requesting it using a simple URL request. Note you will have to use the proper MIMETYPE as you have set it in the format definition above...

Type the following request URL in a web browser:

https://gisedu.itc.utwente.nl/cgi-bin/mapserv.exe?map=[NETPATH]/configWFS.map&SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&TYPENAME=airportsWFS&MAXFEATURES=5&OUTPUTFORMAT=application/json; subtype=geojson

The result should be a GeoJSON file send to your browser...