5.4. WMS GetFeatureInfo access#

The GetFeatureInfo operation (optional) returns information about features near the specified point on the map. Allows users to click on a pixel to query a feature’s schema and metadata.

GetFeatureInfo is an optional operation. This operation is only supported for layers with the attribute queryable="1" (true). If a WMS client makes a request to a layer that does not support this operation, a formatted service exception will be returned.

TA WMS may provide the optional GetFeatureInfo operation, and a WMS that provides this operation calls its map “queryable”. The client can add a position parameter (such as (X, Y) value, that is, the offset from the upper left corner of the picture) or the number of elements that need to query information near the point, to the URL of the requested map, information about the corresponding feature on the map can now be requested.

Since WMS is stateless, the GetFeatureInfo request should also include all the parameters in the original GetMap request (except Version and Request). Based on the spatial context information (BBOX, SRS, Width and Height) in the GetMap request and the (X, Y) location selected by the user, the WMS returns more information about that location.

Also included in the GetFeatureInfo request parameter is the Query_Layers parameter, which specifies the layers from which feature information is obtained. The layers in this parameter list must be those contained in the WMS Capabilities XML document.

The optional Info_Format parameter in the GetFeatureInfo request specifies the format in which the feature’s information is returned. The format is defined as a MIME type in the WMS Capabilities XML document. Such as Info_Format=application/vnd.ogc.gml table does not return results described in GML.

The optional Feature_Count parameter in the GetFeatureInfo request indicates the maximum number of features to return feature information. The default value is 1 . The X,Y parameters represent the pixel coordinates of the point of interest on the map. The X,Y values are within the Width and Height parameter values, respectively. The origin of the coordinates is in the upper left corner of the picture.

If GetFeatureInfo request is valid, WMS will respond according to Info_Format. The nature of the response will be at the discretion of the WMS server, but generally corresponds to the closest element to the point (X,Y).

5.4.1. GetFeatureInfo request using WMS service in MapServer#

This describes the GetFeatureInfo access to the published MapServer WMS service.

The first is Mapfile:

 2    NAME "EX2_"
 3    IMAGETYPE "png24"
 4    EXTENT -180 -90 180 90
 5    SIZE 600 300
 6    SHAPEPATH "/gdata"
 7    SYMBOLSET "../symbols/symbols35.sym"
 8    FONTSET "../fonts/fonts.list"
10        NAME "png"
11        DRIVER "AGG/PNG"
12        MIMETYPE "image/png"
14        EXTENSION "png"
15        FORMATOPTION "GAMMA=0.75"
16    END
17    WEB
18        TEMPLATE "tmpl_ogc.html"
19        IMAGEPATH "/owg/ms_tmp/"
20        IMAGEURL "/ms_tmp/"
21        METADATA
22            "wms_title" "WMS Demo Server"
23            "wms_version" "1.3.0"
24            "wms_onlineresource" "http://webgis.pub/cgi-bin/mapserv?map=/owg/mfb2.map&"
25            "wms_srs" "EPSG:4326"
26            "wms_enable_request" "*"
27            "ows_enable_request" "*"
28            "wms_feature_info_mime_type" "text/html"
29            "wms_format" "image/png"
30        END
31    END
33        "init=epsg:4326"
34    END
35    LAYER
36        NAME "topo"
37        DATA "land_shallow_topo_8192.tif"
38        STATUS OFF
39        TYPE RASTER
40        PROCESSING "BANDS=1,2,3"
41        PROJECTION
42            "init=epsg:4326"
43        END
44    END
45    LAYER
46        NAME "states"
47        DATA "wcountry.shp"
48        STATUS OFF
49        TYPE POLYGON
50        TEMPLATE "tmpl_ogc.html"
51        METADATA
52            "wms_title" "test2"
53            "wms_version" "1.3.0"
54            "wms_srs" "EPSG:4326 EPSG:3857"
55            "wms_enable_request" "*"
56            "ows_enable_request" "*"
57            "wms_feature_info_mime_type" "text/html"
58            "wms_format" "image/png"
59        END
60        PROJECTION
61            "init=epsg:4326"
62        END
63        CLASS
64            NAME "States"
65            STYLE
66                COLOR 232 232 232
67                OUTLINECOLOR 32 32 32
68            END
69        END
70    END
71    LAYER
72        NAME "states_line"
73        DATA "wcountry.shp"
74        STATUS OFF
75        TYPE LINE
76        TEMPLATE "tmpl_ogc.html"
77        METADATA
78            "wms_title" "test3"
79            "wms_version" "1.3.0"
80            "wms_srs" "EPSG:4326 EPSG:3857"
81            "wms_enable_request" "*"
82            "ows_enable_request" "*"
83            "wms_feature_info_mime_type" "text/html"
84            "wms_format" "image/png"
85        END
86        PROJECTION
87            "init=epsg:4326"
88        END
89        CLASS
90            NAME "State Boundary"
91            STYLE
92                COLOR 132 132 32
93            END
94        END
95    END

Compared to the previous mfb1.map:

This Mapfile is configured with the WMS service. View function:

Open a link

5.4.2. View the map#

5.4.3. Access using GetFeatureInfo#

Use GetFeatureInfo

The above results are output using a template. Note#

WMS, Web Mapping Server, is a specification published by OGC.

GetFeatureInfo is an access method supported by WMS.