Main Content

updateLayers

Update layer properties

Description

example

[updatedLayer,index] = updateLayers(server,layer) returns an array of WMSLayer objects and updates the layer properties with values from the web map server, server. The WMSLayer array layer must contain only one unique ServerURL. The updateLayers function removes layers no longer available on the server. The logical array index contains true for each available layer.

Examples

collapse all

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

Search the WMS Database for the layer.

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

Create a web map server object by specifying the server URL of the layer.

server = WebMapServer(modis.ServerURL);

Update the properties of the layer by specifying the server and the layer.

updatedLayer = updateLayers(server,modis);

Read and display the map.

mapRequest = WMSMapRequest(updatedLayer,server);
A = getMap(server,mapRequest.RequestURL);
R = mapRequest.RasterReference;

figure
ax = worldmap('world');
geoshow(A,R)
setm(ax,'MLabelParallel',-90,'MLabelLocation',90)
title({'MODIS Global Mosaic',modis.LayerTitle})

The layer used in this example is courtesy of the NASA Earth Observing System.

Search the WMS Database for layers from USGS servers that contain the word "imagery" in the server URL.

usgsLayers = wmsfind('usgs*imagery','SearchField','serverurl');

Create an array called updatedLayers. Use a loop to find the layers for individual servers, update the properties of the layers, and append the updated layers to the array. Display a message to the command line if a server does not respond.

updatedLayers = [];
serverURLs = usgsLayers.servers;

for k=1:numel(serverURLs)
   serverLayers = refine(usgsLayers, serverURLs{k}, ...
          'SearchField','serverurl','MatchType','exact');
   serverURL = serverLayers(1).ServerURL;
   server = WebMapServer(serverURL);
   try
      layers = updateLayers(server,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 responding.\n', ...
              serverURL);
       fprintf('Error message is %s\n', e.message)
    end
end 

Input Arguments

collapse all

Web map server, specified as an array of WebMapServer objects.

Web map service layer, specified as a WMSLayer object.

Output Arguments

collapse all

Updated web map service layers, returned as an array of WMSLayer objects. updatedLayers has the same size as layer(index).

Availability of layers, returned as a logical array. index contains true for each available layer.

Tips

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

Introduced before R2006a