Main Content

Display a World Map

This example shows how to access imagery from the United States Geological Survey (USGS) National Map SOAP server. To create the map, you need the following information.

  • Get a map tile.

  • Get the map name.

  • Get the format of the tiles.

This example shows you how to call functions in the USGS web service, USGSImageryOnly_MapServer, to get this information.

Install the Java® JDK™ and Apache® CXF programs and set the tool paths to run this example.

p = matlab.wsdl.setWSDLToolPath;
if (isempty(p.JDK) || isempty(p.CXF))
    disp('Install the Java Development Kit (JDK) and Apache CXF programs.')
    disp('See the Set Up WSDL Tools link at the end of this example.')
else
    disp('Paths set to:')
    matlab.wsdl.setWSDLToolPath
end

Change your current folder to a writable folder.

Assign the WSDL URL.

wsdlFile = ...
'http://basemap.nationalmap.gov/arcgis/services/USGSImageryOnly/MapServer?wsdl';

Create the class files for the client.

matlab.wsdl.createWSDLClient(wsdlFile)
Created USGSImageryOnly_MapServer.
  .\USGSImageryOnly_MapServer.m
  .\+wsdl

In order to use USGSImageryOnly_MapServer, you must run javaaddpath('.\+wsdl\mapserver.jar').

ans = 

    @USGSImageryOnly_MapServer

Add the jar files to the Java path.

javaaddpath('.\+wsdl\mapserver.jar')

Start the service.

wsdl = USGSImageryOnly_MapServer;

Explore the service.

help USGSImageryOnly_MapServer
USGSImageryOnly_MapServer   A client to connect to the USGSImageryOnly_MapServer service
     SERVICE = USGSImageryOnly_MapServer  connects to http://basemap.nationalmap.gov/arcgis/services/USGSImageryOnly/MapServer and returns a SERVICE.
     
     To communicate with the service, call a function on the SERVICE:
 
        [...] = FUNCTION(SERVICE,arg,...) 
 
     See doc USGSImageryOnly_MapServer for a list of functions.

Click the link doc USGSImageryOnly_MapServer. MATLAB® opens a reference page for USGSImageryOnly_MapServer in the Help browser.

Read the documentation for the required inputs to the GetMapTile function.

help GetMapTile
 --- help for USGSImageryOnly_MapServer/GetMapTile ---

 GetMapTile  
   Result = GetMapTile(obj,MapName,Level,Row,Column,Format)  
     Inputs:
       obj - USGSImageryOnly_MapServer object
       MapName - string
       Level - numeric scalar (XML int)
       Row - numeric scalar (XML int)
       Column - numeric scalar (XML int)
       Format - string
     Output:
       Result - vector of numbers 0-255 (XML base64Binary)
 
  See also USGSImageryOnly_MapServer.

You need MapName, Level, Row, Column, and Format input arguments.

Read the documentation for a function that provides a map name, GetDefaultMapName.

help GetDefaultMapName
--- help for USGSImageryOnly_MapServer/GetDefaultMapName ---

 GetDefaultMapName  
   Result = GetDefaultMapName(obj)  
     Inputs:
       obj - USGSImageryOnly_MapServer object
     Output:
       Result - string
 
  See also USGSImageryOnly_MapServer.

This function provides a map name.

Read the documentation for a function that provides a map format information, GetTileImageInfo.

help GetTileImageInfo
--- help for USGSImageryOnly_MapServer/GetTileImageInfo ---

 GetTileImageInfo  
   Result = GetTileImageInfo(obj,MapName)  
     Inputs:
       obj - USGSImageryOnly_MapServer object
       MapName - string
     Output:
       Result - TileImageInfo object
 
  See also USGSImageryOnly_MapServer.

This function returns a TileImageInfo object.

Read the documentation for the TileImageInfo object by clicking the link in the help display to TileImageInfo.

TileImageInfo(CacheTileFormat,CompressionQuality,Antialiasing)  TileImageInfo object for use with USGSImageryOnly_MapServer web client
 
      CacheTileFormat - string
          The cache tile format.
      CompressionQuality - numeric scalar (XML int)
          The cache tile image compression quality.
      Antialiasing - string
See also
USGSImageryOnly_MapServer.

MATLAB opens a document in the Help browser. The format information is CacheTileFormat.

Create the JPEG data. The following code requires knowledge of the JPEG image format and the tiling scheme used by the USGS server.

% Get the default map name.
defaultMapName = GetDefaultMapName(wsdl);

% Get the map count.
count = GetMapCount(wsdl);

% Get the map name. There is only one map (count value),
% but the index is zero-based.
mapName = GetMapName(wsdl, count-1);

% Get information about the tiles.
tileImageInfo = GetTileImageInfo(wsdl, mapName);

% Get the format of the data.
format = tileImageInfo.CacheTileFormat;

% Since format is specified as 'Mixed' it implies that 
% the result of GetMapTile is a JPEG-encoded stream.
% The map tiles are organized with the lowest level as 
% the lowest level of detail and the tiles use 
% zero-based indexing.
level = 0; 
row = 0; 
col = 0; 
jpeg = GetMapTile(wsdl,mapName,level,row,col,format); 

Write the JPEG-encoded data to a file. Use imread to read and decode the JPEG data and return an M-by-N-by-3 uint8 matrix.

ext = '.jpg'; 
tilename = ['USGSImageryOnly_MapServer' '0_0_0' ext]; 
fid = fopen(tilename,'w'); 
fwrite(fid,jpeg)
fclose(fid)

View the map.

tileImage = imread(tilename);
figure
imshow(tileImage) 

Related Topics