世界地図の表示
この例では、米国地質調査所 (USGS) の National Map SOAP サーバーのイメージにアクセスする方法を説明します。マップを作成するには、次の情報が必要です。
マップ タイルの取得。
マップ名の取得。
タイルの形式の取得。
この例では、USGS の Web サービスの関数 USGSImageryOnly_MapServer を呼び出してこの情報を取得する方法を説明します。
Java® JDK™ および Apache® CXF プログラムをインストールし、ツール パスを設定して次の例を実行します。
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
現在のフォルダーを書き込み可能なフォルダーに変更します。
WSDL の URL を割り当てます。
wsdlFile = ... 'http://basemap.nationalmap.gov/arcgis/services/USGSImageryOnly/MapServer?wsdl';
クライアントのクラス ファイルを作成します。
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
jar ファイルを Java パスに追加します。
javaaddpath('.\+wsdl\mapserver.jar')サービスを起動します。
wsdl = USGSImageryOnly_MapServer;
サービスについて調べます。
help USGSImageryOnly_MapServerUSGSImageryOnly_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.リンク doc USGSImageryOnly_MapServer をクリックします。MATLAB® によりシステムの Web ブラウザーに USGSImageryOnly_MapServer のリファレンス ページが開きます。
関数 GetMapTile に必要な入力のドキュメンテーションを読みます。
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.
MapName、Level、Row、Column および Format の入力引数が必要です。
マップ名 GetDefaultMapName を提供する関数のドキュメンテーションを読みます。
help GetDefaultMapName--- help for USGSImageryOnly_MapServer/GetDefaultMapName ---
GetDefaultMapName
Result = GetDefaultMapName(obj)
Inputs:
obj - USGSImageryOnly_MapServer object
Output:
Result - string
See also USGSImageryOnly_MapServer.関数がマップ名を提供します。
マップ形式情報 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.この関数は、TileImageInfo オブジェクトを返します。
TileImageInfo のヘルプ表示にあるリンクをクリックして 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 によりシステムの Web ブラウザーにドキュメントが開きます。形式情報は、CacheTileFormat です。
JPEG データを作成します。次のコードには JPEG イメージ形式と USGS サーバーが使用するタイル配置の知識が必要です。
% 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);
JPEG エンコード データをファイルに書き込みます。imread を使用して JPEG データを読み取ってデコードし、M x N x 3 の uint8 の行列を返します。
ext = '.jpg'; tilename = ['USGSImageryOnly_MapServer' '0_0_0' ext]; fid = fopen(tilename,'w'); fwrite(fid,jpeg) fclose(fid)
マップを表示します。
tileImage = imread(tilename); figure imshow(tileImage)