Class: WebMapServer

Update layer properties


[updatedLayer, index] = updateLayers(server,layer)


[updatedLayer, index] = updateLayers(server,layer) returns a WMSLayer array with properties updated with values from server, a WebMapServer object. The WMSLayer array Layer must contain only one unique ServerURL. The updateLayers method removes layers no longer available on the server. The logical array index contains true for each available layer, such that updatedLayers has the same size as layer(index).

The updateLayers method accesses the Internet to update the properties. Occasionally, a WMS server is unavailable, or several minutes elapse before the properties are updated.


Update the properties of a MODIS global mosaic layer obtained from the NASA Earth Observations WMS server.

nasa = wmsfind('NASA Earth Observations', 'SearchField', 'any');
modis = refine(nasa, 'land*day*month');
modis = modis(1); 

% Create a WebMapServer object. 
server = WebMapServer(modis.ServerURL); 
% Update the properties of the modis layer. 
updatedLayer = updateLayers(server,modis); 

% View the metadata of the layer. 
metadata = urlread(updatedLayer.Details.MetadataURL); 

% Obtain and display the map. 
mapRequest = WMSMapRequest(updatedLayer, server); 
A = getMap(server,mapRequest.RequestURL);
R = mapRequest.RasterRef; 
worldmap world 
geoshow(A, R) 
title({'MODIS Global Mosaic','Courtesy NASA Earth Observatory'}) 

Update the properties of layers from multiple servers. Find layers from USGS servers with the name geology in the server URL.

usgs = wmsfind('*geology', 'SearchField', 'serverurl');

Find the layers for an individual server USGS layers, update their properties, and append them to the updatedLayers array.

serverURLs = servers(usgs);
updatedLayers = [];
fprintf('Updating layer properties from %d servers.\n', ...

for k=1:numel(serverURLs)
    serverURL = serverURLs{k};
    serverLayers = refine(usgs, serverURL, ...
        'SearchField', 'serverurl', 'MatchType', 'exact');
    fprintf('Updating properties from server %d:\n%s\n', ...
        k, serverURL);
    wms = WebMapServer(serverURL);
        layers = updateLayers(wms, serverLayers);
        % Grow using concatenation because layers can have  
        % any length ranging from 0 to numel(serverLayers).
        updatedLayers = [updatedLayers; layers];
    catch e
        fprintf('Server %s is not available.\n', serverURL);
        fprintf('Error message is %s\n', e.message)
Was this topic helpful?