[MapServer-users] How to get a WMS GetFeatureInfo response with MapServer in JSON format ?

Rahkonen Jukka jukka.rahkonen at maanmittauslaitos.fi
Thu Sep 14 07:13:53 PDT 2023


Hi,

To those who try to help, please have a look at the same question in gis.stackexchange https://gis.stackexchange.com/questions/466896/how-to-get-a-wms-getfeatureinfo-response-with-mapserver-in-json-format/466920?
There is an answer that gives half an answer, but a remaining problem is how to insert raster layer attributes into a JSON template.

-Jukka Rahkonen-

Lähettäjä: MapServer-users <mapserver-users-bounces at lists.osgeo.org> Puolesta Julien Hubert
Lähetetty: torstai 14. syyskuuta 2023 11.26
Vastaanottaja: mapserver-users at lists.osgeo.org
Aihe: [MapServer-users] How to get a WMS GetFeatureInfo response with MapServer in JSON format ?

Hi,
I use Mapserver with the Leaflet JS library and I want to display some attributes informations by clicking on the map.
Therefore I use the GetFeatureInfo WMS request in order to return these informations.
I managed to get the infos with the text/html format but I'd like to get a JSON response back in my browser, e.g :
{
    "value": [value_0], // I must precise I use GetFeatureInfo on a raster
}

So I changed the wms_get_feature_info_formalist in the METADATA bloc of my mapfile :
"wms_getfeatureinfo_formatlist" "application/json"

Then, I edited my template as following to return the value of the pixel :
<!-- MapServer Template -->
[value_0]

My GetFeatureInfo request is the one (see "application/json" specified in the INFO_FORMAT parameter)

http://IP/cgi-bin/mapserv?map=/var/www/html/mapfiles/test1.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&BBOX=465348.6282001531,5431156.607774916,697564.3201305186,5503160.28841955&SRS=EPSG:3857&WIDTH=1519&HEIGHT=471&LAYERS=layer1&STYLES=&FORMAT=image/png&TRANSPARENT=true&QUERY_LAYERS=layer1&INFO_FORMAT=application/json&X=766&Y=261

But when I try the GetFeatureInfo request, my browser returns nothing (whereas it works with the text/html) and it downloads a file called "mapserv" with nothing inside :
[enter image description here]<https://i.stack.imgur.com/GuVAe.png>

I must explain I don't want to download a GeoJSON file but to return the content of a JSON response in my browser.
Do you know how I could get my JSON response ? Is it possible to make it work ?
Any help would be greatly appreciated, thanks !

--
Julien H
Back-end developper
Forum des Marais Atlantiques
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20230914/4a7b0699/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 3277 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20230914/4a7b0699/attachment-0001.png>


More information about the MapServer-users mailing list