Enable GeoJSON output format in MapServer to be used in an OpenLayers client
Overview
A few customers have asked if it is possible to retrieve data layers from a WFS in GeoJSON format, the answer is Yes. Just follow the steps below.
Step-by-step guide
First you need to add the following to your map file.
OUTPUTFORMAT
NAME "geojson"
DRIVER "OGR/GEOJSON"
MIMETYPE "application/json; subtype=geojson"
FORMATOPTION "STORAGE=stream"
FORMATOPTION "FORM=SIMPLE"
END
For example:
Then you need to add the following two options to your LAYER or MAP METADATA
"wfs_getfeature_formatlist” "geojson"
For example:
Now in your WFS call add the following &outputformat=geojson. This will return GeoJSON directly in the browser, if you need it to download, you can change the FORMATOPTION to FORM=ZIP.
For more information please see the MapServer documentation - http://mapserver.org/output/ogr_output.html.