[MapServer-users] WFS, OpenLayers and OUTPUTFORMAT explanations

mathias cunault mathias.cunault at inrap.fr
Fri Mar 22 03:23:55 PDT 2024


Thanks,
After some tests and internet searchs, as soon as NAME is set to geojson, I
can use either # MIMETYPE "application/json;subtype=geojson" or
MIMETYPE "geojson" or MIMETYPE "application/geo+json". The thing to avoid
is NAME application/json.

Cordialement,

*----------*
*Mathias Cunault*

*référent SIG / Admin Caviar*

*Inrap Tours - 148 av. Maginot37000 TOURS06 32 05 98 96*
abonnez-vous à la lettre d'information de l'Inrap : http://ww
<http://www.inrap.fr/newsletter.php>w.inrap.fr/newsletter.php
<http://www.inrap.fr/newsletter.php>


Le mer. 20 mars 2024 à 22:50, Seth G <sethg at geographika.co.uk> a écrit :

> 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/20240322/32d0fe9d/attachment.htm>


More information about the MapServer-users mailing list