Main Content

Modify Your Map Request

Set Map Request Geographic Limits and Time

A WMSMapRequest object contains properties to modify the geographic extent and time of the requested map. This example shows how to modify your map request to map land surface temperature for the southern tip of Africa. For a complete list of properties, see WMSMapRequest.

Search the WMS Database for layers on the NASA Earth Observations (NEO) WMS server. Refine the search to include only layers with "land surface temperature" in the layer title or layer name. Refine the search again to include only the layer with monthly values from the MODIS sensor on the Terra satellite.

neo = wmsfind("neo*nasa*wms","SearchFields","serverurl");
landTemp = refine(neo,"land surface temperature");
landTemp = refine(landTemp,"night*month*modis");
landTemp = wmsupdate(landTemp);

Create a WebMapServer object from the server URL stored in the ServerURL property of the layer.

server = WebMapServer(landTemp.ServerURL);

Create a WebMapRequest object from the layer and web map server object. Set the latitude and longitude limits by using the Latlim and Lonlim properties. Set the time request to March 1, 2009 by using the Time property.

mapRequest = WMSMapRequest(landTemp,server);
mapRequest.Latlim = [-45 -25];
mapRequest.Lonlim = [15 35];
mapRequest.Time = "2009-03-01";

Send your request to the server by using the getMap function.

landTempImage = getMap(server,mapRequest.RequestURL);

Display the image on a map.

figure
worldmap(mapRequest.Latlim,mapRequest.Lonlim);
setm(gca,"mlabelparallel",-45)
geoshow(landTempImage,mapRequest.RasterReference);
title(["South Africa" landTemp.LayerTitle], ...
    "FontWeight","bold","Interpreter","none")

Read abstract information for the layer from the MetadataURL field.

readerFcn = @(filename)readstruct(filename,"FileType","xml");
options = weboptions("ContentReader",readerFcn,"Timeout",10);
xml = webread(landTemp.Details.MetadataURL,options);
abstract = xml.idinfo.descript.abstract;

Manually Edit Web Map Request URL

You can modify a map request URL manually.

Search the WMS Database for a layer containing terrain elevation data from the WMS server hosted by MathWorks®. Get the map request URL for the layer.

layers = wmsfind("mathworks","SearchField","serverurl");
layer = refine(layers,"elevation");
mapRequest = WMSMapRequest(layer);

Set the map request URL to a variable.

mapURL = mapRequest.RequestURL;

Specify a background color and request data for the southern hemisphere by manually editing the map request URL. To do this, copy and paste the contents of mapURL into a new variable. Then, change the background color section of the URL to &BGCOLOR=0x2DC1D2 and change the bounding box section of the URL to &BBOX=-90.0,-180,0,180.0.

modifiedURL = ['https://wms.mathworks.com?SERVICE=WMS' ...
                '&LAYERS=terrain&CRS=EPSG:4326&FORMAT=image/png' ...
                '&TRANSPARENT=FALSE&HEIGHT=256&BGCOLOR=0x2DC1D2' ...
                '&REQUEST=GetMap&WIDTH=512&BBOX=-90.0,-180,0,180.0' ...
                '&STYLES=&VERSION=1.3.0'];

Read and display the modified map.

[A,R] = wmsread(modifiedURL);
figure
axesm globe
axis off
geoshow(A,R)
title("Terrain Data for the Southern Hemisphere")

See Also

| |

Related Topics