[MapServer-users] WFS, OpenLayers and OUTPUTFORMAT explanations

Seth G sethg at geographika.co.uk
Wed Mar 20 14:49:37 PDT 2024


Hi,

Probably best to check the WFS service GetCapabilities document to check which formats are supported. 
(From memory) wfs_getfeature_formatlist can include either the NAME or the MIMETYPE of the OUTPUTFORMAT.
You have MIMETYPE set to "application/json;subtype=geojson", so maybe try chaging this to "application/json" or changing the NAME from "geojson" to ""application/json" to get an exact match. 

Seth

--
web:https://geographika.net & https://mapserverstudio.net
twitter: @geographika

On Tue, Mar 19, 2024, at 11:26 AM, mathias cunault via MapServer-users wrote:
> Hello,
> Something that was never clear to me.
> Here is a mapfile for a WFS definition:
> MAP
> NAME "Mapserver-Inrap"
> FONTSET "C:\ms4w\Apache\site\fonts\fonts.txt"
> OUTPUTFORMAT
> NAME "geojson"
> DRIVER "OGR/GEOJSON"
> MIMETYPE "application/json;subtype=geojson" #option
> # FORMATOPTION "STORAGE=stream" #requis
> # FORMATOPTION "FORM=SIMPLE"
> FORMATOPTION "STORAGE=memory" #requis
> FORMATOPTION "FORM=SIMPLE"
> END #fin format
> 
> EXTENT 103362.94 6049964.789658545 1242388.010000001 7108973.60237487 #xmin ymin xmax ymax
> 51.075383199990654 #xmin ymin xmax ymax
> UNITS METERS
> DEBUG 5
> CONFIG "CPL_DEBUG" "ON"
> CONFIG "PROJ_DEBUG" "ON"
> CONFIG MS_ERRORFILE "C:/ms4w/Apache/error/errorMapFile_vue_ol_prescription.txt"
> 
> SYMBOLSET "C:\ms4w\Apache\site\symbols\symbols.sym"
> 
> PROJECTION # proj de sortie
> "init=epsg:2154"
> END
> 
> WEB 
> METADATA
> "wfs_title" "WFS Caviar"
> "wfs_onlineresource" "http://xxxx/mapserv.exe?MAP=C:/ms4w/Apache/site/mapfile/vue_ol_prescription.map"
> "wms_encoding" "UTF-8"
> "wfs_srs" "EPSG:2154 EPSG:32620 EPSG:3857 EPSG:900913 EPSG:4326"
> "wfs_enable_request" "*"
> "wfs_abstract" "blabla"
> "wfs_getfeature_formatlist" "application/json, GeoJSON, json"
> END #fin metadata
> END #end web
> 
> #-----debut prescription
> LAYER
> NAME "prescription"
> TYPE POLYGON
> CONNECTIONTYPE POSTGIS
> CONNECTION "host=xxx dbname=activite user=wxxx password=xxx port=5432"
> DATA "geom from activite.vue_ol_prescription using unique gid using SRID=2154"
> EXTENT 103362.94 6049964.789658545 1242388.010000001 7108973.60237487 #aide pour performance
> PROCESSING "CLOSE_CONNECTION=DEFER"
> CLASS
> ...
> END #-----fin classe unique
> METADATA
> "gml_include_items" "all" #obligé pour afficher attributs getfeatureinfo
> "wfs_title" "prescription_2154"
> #d'après la doc pas besoin si défini dans les metadata de la map cf.10.1
> #"wfs_srs" "EPSG:2154"
> "gml_featureid" "gid"
> "wfs_enable_request" "*"
> "wfs_use_default_extent_for_getfeature" "false"
> # si geojson en premier alors geoson dans l'url pour OpenLayers:
> "wfs_getfeature_formatlist" "GeoJSON, json, application/json"
> END #fin metadata prescription
> TEMPLATE "bidon.html"
> END #fin layer prescription
> 
> END #-----fin mapfile
> 
> It works fine in QGIS.
> In a javascript file with the OpenLayers library, I can define a source with an url function like this:
>  url: function (extent) {
>     return (
>       "http://xxxx/cgi-bin/mapserv.exe?MAP=C:/.../vue_ol_prescription.map&" +
>       "service=WFS&version=1.1.0&request=GetFeature&typename=prescription&" +
>       "outputformat=geojson&SRSNAME=EPSG:2154&bbox=" +
>       extent.join(",") +
>       ",EPSG:3857"
>     )
> 
> Why can't I use outputformat = application/json though it is permitted by the outpuformat in mapfile layer definition ? I have an error : "application.json  not permitted".
> Leehan
> _______________________________________________
> MapServer-users mailing list
> MapServer-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/mapserver-users
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20240320/ba134cee/attachment.htm>


More information about the MapServer-users mailing list