WMS GetFeatureInfo – Prevent Geometry Return in MapServer 6.4

getfeatureinfomapserverwms

When I send a GetFeatureInfo request to my Mapserver 6.4 WMS, the response contains the geometry. I want to disable this, as it is far too large in size. However, I am serving the same data as a WFS from Mapserver, and don't want to lose geometry from that.

Elsewhere, I was told to try the following in my mapfile's metadata:

wfs_mygeom_type "multipolygon"
wfs_geometries "mygeom"

This has no effect for me – geometry is still returned for a WMS GetFeatureInfo request.

How do I prevent geometry returning in WMS GetFeatureInfo only?

Best Answer

(for other readers: this was initially asked on Twitter, and I answered there at https://twitter.com/mapserving/status/1428728627076780036 )

Here is my mapfile that was used for that answer, that disables geometry for WMS GetFeatureInfo requests, and enables geometry for WFS GetFeature requests (see settings in LAYER "countries" metadata object):

    *
 Description:  Simple map to test geometry output for WMS/WFS ( on https://ms4w.dev )
 Data source:  NaturalEarth dataset, in SpatiaLite format.
 Other notes:  Open this mapfile in Notepad++, and use the color syntax file
               from https://ms4w.com/trac/wiki/Notepad++MapServerStyle
 Author:       Jeff McKenna, GatewayGeo, [email protected]
 Last updated: 2021-08-20
*/
 
MAP
NAME "geom-test"
STATUS ON
SIZE 600 400
SYMBOLSET "../etc/symbols.txt"
EXTENT -180 -90 180 90
UNITS DD
SHAPEPATH "./data"
IMAGECOLOR 255 255 255
FONTSET "../etc/fonts.txt"
PROJECTION
  "init=epsg:4326"
END  

WEB
  IMAGEPATH "/ms4w/tmp/ms_tmp/" 
  IMAGEURL "/ms_tmp/"
  METADATA
    "ows_title"             "MS4W Demo WMS Server"
    "ows_abstract"          "This demonstration server was setup by GatewayGeo (https://gatewaygeomatics.com/) and is powered by MS4W (https://ms4w.com/)."      
    "ows_onlineresource"    "https://ms4w.dev/cgi-bin/mapserv.exe?map=/ms4w/apps/local-demo/geom-test.map"
    "ows_service_onlineresource" "https://gatewaygeomatics.com/"    
    "ows_contactperson"     "Jeff McKenna" 
    "wms_contactorganization" "GatewayGeo"
    "ows_contactposition"   "President"
    "ows_contactelectronicmailaddress" "[email protected]"
    "ows_srs"               "EPSG:4326 EPSG:3857 EPSG:4269"
    "ows_getfeatureinfo_formatlist" "text/plain,text/html,application/json,application/vnd.ogc.gml,gml"
    "ows_enable_request"    "*"
  END
END

OUTPUTFORMAT
  NAME "png"
  DRIVER AGG/PNG
  MIMETYPE "image/png"
  IMAGEMODE RGB
  EXTENSION "png"
  FORMATOPTION "GAMMA=0.75"
END

OUTPUTFORMAT
  NAME "application/json"
  DRIVER "OGR/GEOJSON"
  MIMETYPE "application/json"
  FORMATOPTION "FORM=SIMPLE"
  FORMATOPTION "STORAGE=memory"
END

/* Countries */
LAYER
  NAME "countries"
  METADATA
    "ows_title"         "World Countries"
    "wms_include_items" "all"
    "gml_include_items" "all"
    "gml_featureid"     "ogc_fid"
    "wfs_mygeom_type"   "multipolygon"
    "wfs_geometries"    "mygeom"
  END
  TYPE POLYGON
  STATUS ON
  CONNECTIONTYPE OGR
  CONNECTION "demo.db"
  DATA "countries"
  PROJECTION
    "init=epsg:4326"
  END
  LABELITEM "name"
  CLASS
    NAME "World Countries"
    STYLE
      COLOR 200 200 200
      OUTLINECOLOR 0 0 0
      WIDTH 0.1
    END
    LABEL
      FONT sans
      TYPE truetype
      POSITION AUTO     
      PARTIALS FALSE
      BUFFER 5
      SIZE 5 
      COLOR 75 75 75
      MINFEATURESIZE 10
    END     
  END
  TEMPLATE "ttt.html"  
END # layer

END # Map File

Happy mapserving!

-jeff

--
GatewayGeo: Developers of MS4W, MapServer Consulting and Training
co-founder of FOSS4G
http://gatewaygeo.com/