5.3. Use WMS Services GetMap in MapServer#

The GetMap operation is used to generate a map, which can be a picture or a set of graphic elements. GetMap allows clients to request multiple servers to make overlapping map layers, processing pixel geometry with the same frame of reference, size, and scale. These layers can be displayed in a certain order on the client side, and transparent pixel technology can be used to display map information from different sources according to human visualization requirements.

The GetMap request usually uses HTTP/GET to call a basic WMS via URL encoding, and can also use HTTP/POST encoding to communicate with an SLD-capable WMS. The GetMap request must specify the requested layers (Layers), the styles used by each layer (Styles), the spatial reference system (SRS), the bounding rectangle (BBox), the image format ( format ) and size ( width , height ) and other parameters.

Web map services support the display of map views in picture or graphic format. Image formats include public image formats such as GIF, PNG, JPEG, etc. These formats are supported by most Web browsers, and the display of other graphic formats may also require some helper programs to support. Graphics formats include SVG and WebCGM formats, which are not commonly used in WMS.

In addition, the optional transparent parameter is used to specify whether the background of the map is transparent. The default value is False . A function that allows the returned result to be drawn transparently, so that maps for different requests can be overlaid. Each WMS preferably provides an image format that supports transparent display for overlaying with other map images.

A valid GetMap request will return a map consisting of georeferenced layers with the specified style, spatial reference system, bounding rectangle, size, format, and transparency. An invalid GetMap request returns a formatted error message. In the HTTP context, the content type of the return value is a MIME type.

5.3.1. Request with GetMap#

GetMap access to the published MapServer WMS service is described here.

The first is Mapfile:

 1MAP
 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"
 9    OUTPUTFORMAT
10        NAME "png"
11        DRIVER "AGG/PNG"
12        MIMETYPE "image/png"
13        IMAGEMODE RGB
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
32    PROJECTION
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
96END

Compared to the previous mfa1.map:

diff_mfb1_mfa1.html

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

Open a link

5.3.2. View the map#

Here, use the map mode of MapServer to view.

http://webgis.pub/cgi-bin/mapserv?map=/owg/mfb2.map&layer=states&mode=map

View the map#

5.3.3. Configure with GetMap#

Without GetMap enabled#

To use GetMap request, you need to enable the GetMap option for WMS in Mapfile :

If not enabled, it will show the following result as the result of the request to the URL :

<ServiceExceptionReport version="1.3.0" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd"><ServiceException>
msWMSDispatch(): WMS server error. WMS request not enabled. Check wms/ows_enable_request settings.
</ServiceException></ServiceExceptionReport>

Projection for WMS#

Note that to use GetMap request , the projection must be set. If it is not set, the access will appear:

<ServiceExceptionReport version="1.3.0" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd"><ServiceException code="InvalidCRS">
msWMSLoadGetMapParams(): WMS server error. Cannot set new CRS on a map that doesn't have any projection set. Please make sure your mapfile has a projection defined at the top level.
</ServiceException></ServiceExceptionReport>

Yo can click the link to view the actual Error result page.

Request the WMS#

Here is the correct way to access it. Note that the length and width parameters passed to the server graph in URL.

It looks like that the GETMAP request result is similar to MapServer’s mode=map.

http://webgis.pub/cgi-bin/mapserv?map=/owg/mfb2.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMAP&LAYERS=states&BBOX=-180,-90,180,90&CRS=CRS:84&INFO_FORMAT=text/html&format=image/png&width=200&height=150&styles=

Use GetMap

Note

Version of WMS 1.1.1 and WMS 1.3.0 have different request parameter for coordinate system :

  • SRS=EPSG:4326 for 1.1.1

  • CRS=CRS:84 for 1.3.0

5.3.4. Get a partial map with GetMap#

The range used above is consistent with the range of the entire data, and the results look no different. Let’s zoom out to get a section of the map.

http://webgis.pub/cgi-bin/mapserv?map=/owg/mfb2.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMAP&LAYERS=states&BBOX=73,3,136,54&CRS=CRS:84&INFO_FORMAT=text/html&format=image/png&width=200&height=150&styles=

Get a partial map with GetMap

According to the description, the parameter CRS = EPSG: 4326 can also be used. But I didn’t succeed. You may need to configure mapfile.

The above effect can also be achieved in MapServer CGI control, by setting the zoom level of browsing, the x and y coordinates of the map but GetMap is obviously more flexible. In addition to these, WMS has more advantages as a standard.