Documentation Center

  • Trial Software
  • Product Updates

updateLayers

Class: WebMapServer

Update layer properties

Syntax

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

Description

[updatedLayer, index] = server.updateLayers(layer) returns a WMSLayer array with properties updated with values from the server. 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.

Examples

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 = server.updateLayers(modis); 

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

% Obtain and display the map. 
mapRequest = WMSMapRequest(updatedLayer, server); 
A = server.getMap(mapRequest.RequestURL); 
R = mapRequest.RasterRef; 
figure 
worldmap world 
geoshow(A, R) 
setm(gca,'MLabelParallel',-90,'MLabelLocation',90) 
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('usgs.gov*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', ...
    length(serverURLs));

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);
    try
        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)
    end
end
Was this topic helpful?