ラベル WMS GetCapabilitis の投稿を表示しています。 すべての投稿を表示
ラベル WMS GetCapabilitis の投稿を表示しています。 すべての投稿を表示

2015年2月16日月曜日

2 - ol3.2ex 59b - WMS GetCapabilities parsing example 2

「wms-capabilities.js(259-ol3ex.js)」は、マップを表示するための JavaScript ファイルです。

「ogcsample.xml」
<?xml version='1.0' encoding="UTF-8"?>
<WMS_Capabilities version="1.3.0" xmlns="http://www.opengis.net/wms"
 xmlns:xlink="http://www.w3.org/1999/xlink"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd">
<Service>
 <Name>WMS</Name>
 <Title>Acme Corp. Map Server</Title>
 <Abstract>Map Server maintained by Acme Corporation.  Contact: webmaster@wmt.acme.com.  High-quality maps showing roadrunner nests and possible ambush locations.</Abstract>
 <KeywordList>
  <Keyword>bird</Keyword>
  <Keyword>roadrunner</Keyword>
  <Keyword>ambush</Keyword>
 </KeywordList>
 <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple"
  xlink:href="http://hostname/" />
 <ContactInformation>
  <ContactPersonPrimary>
   <ContactPerson>Jeff Smith</ContactPerson>
   <ContactOrganization>NASA</ContactOrganization>
  </ContactPersonPrimary>
  <ContactPosition>Computer Scientist</ContactPosition>
---

「259-ol3ex.js」
var parser = new ol.format.WMSCapabilities();
/** ol.format.WMSCapabilities
 * Format for reading WMS capabilities data
 * WMS capabilities データを読み込むためのフォーマット。
 * (ol3 API)
 */
// $.ajax('data/ogcsample.xml').then(function(response) {
$.ajax('v3.2.0/examples/data/ogcsample.xml').then(function(response) {
/** jQuery.ajax()
 * Perform an asynchronous HTTP (Ajax) request.
 * 非同期 HTTP(Ajax)リエストを実行します。
 * (jQuery[http://api.jquery.com/jquery.ajax/])
 */
/** deferred.then()
 * Add handlers to be called when the Deferred object is 
 * resolved, rejected, or still in progress. 
 * deferred オブジェクトが resolved、rejected か、まだ処理途中
 * (progress)のとき呼び出されるハンドラを追加します。
 * (juery[http://api.jquery.com/deferred.then/])
 */
 var result = parser.read(response);
 /** read()
  * Read a WMS capabilities document.
  * (v3.2.0/ol/ol/format/wmscapabilities)
  */
 $('#log').html(window.JSON.stringify(result, null, 2));
 /** .html()
  * Get the HTML contents of the first element in the 
  * set of matched elements or set the HTML contents of 
  * every matched element.
  * 一致した要素のセット、または、すべての一致した要素のHTML
  * コンテンツのセットの最初の要素のHTMLコンテンツを取得します。
  * (jQuery[http://api.jquery.com/html/])
  */
 /** JSON.stringify()
  * The JSON.stringify() method converts a JavaScript 
  * value to a JSON string, optionally replacing values 
  * if a replacer function is specified, or optionally 
  * including only the specified properties if a 
  * replacer array is specified.
  * JSON.stringify()メソッドは、JavaScript の値を JSON 文
  * 字列に変換します。replacer function が指定されている場合は
  * 必要に応じて値を置換し、または、replacer 配列が指定されている
  * 場合は必要に応じて指定されたプロパティのみを含みます。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * JavaScript/Reference/Global_Objects/JSON/stringify])
  */
});


.then() に関しては、
「爆速でわかるjQuery.Deferred超入門(http://techblog.yahoo.co.jp/programming/jquery-deferred/)」なども参考にしてください。

2 - ol3.2ex 59a - WMS GetCapabilities parsing example 1

「WMS GetCapabilities parsing example(wms-capabilities.html)」を参考に地図を表示してみます。

HTML ファイルの作成
a Eclipse のメニューの「ファイル」->「ファイルを開く」をクリックします。





b 「ファイルを開く」ウィンドウで、「user」->「mapsite」->「ol3proj」->「v3.2.0」->「examples」->「wms-capabilities.html」をクリックして選択し、「OK」ボタンをクリックします。
同じように「wms-capabilities.js」を開きます。





c メニューの「ファイル」->「新規」 -> 「ファイル」をクリックします。



d 「ファイル」ウィンドウで「ol3proj」をクリックして選択し、「ファイル名」を「259-ol3ex.html」と入力し、「次へ」ボタンをクリックします。








e 「File Template」ウィンドウで「HTML 5 Template」をクリックして選択し、「OK」ボタンをクリックします。











f 「wms-capabilities.html」の内容をコピーして「259-ol3ex.html」に貼り付け、修正します。
g 同じように、新規に「259-ol3ex.js」ファイルを作成し、「File Template」ウィンドウで「JavaScript Template」をクリックして選択し、「完了」ボタンをクリックして、「wms-capabilities.js」の内容をコピーして貼り付け、修正します。「wms-capabilities-require.js」も「259-ol3ex-require.js」に貼り付けます。



「259-ol3ex.html」
<!doctype html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="chrome=1">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<!--
  <link rel="stylesheet" href="../css/ol.css" type="text/css">
  <link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="../resources/layout.css" type="text/css">
  <link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
-->
  <!-- ディレクトリ修正 -->
  <link rel="stylesheet" href="v3.2.0/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.2.0/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.2.0/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.2.0/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>WMS GetCapabilities parsing example</title>
 </head>
 <body>
  <!-- 
  bootstrap.min.css, bootstrap-responsive.min.css で設定されたセレクタを使用。
  -->
  <div class="navbar navbar-inverse navbar-fixed-top">
   <div class="navbar-inner">
    <div class="container">
     <!--
     <a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
     -->
      <!-- ディレクトリ修正 -->
     <a class="brand" href="v3.2.0/examples/"><img src="v3.2.0/resources/logo.png"> OpenLayers 3 Examples</a>
    </div>
   </div>
  </div>
  <div class="container-fluid">
   <div class="row-fluid">
    <div class="span4">
     <h4 id="title">WMS GetCapabilities parsing example</h4>
     <p id="shortdesc">Example of parsing a WMS GetCapabilities response.</p>
     <div id="docs">
      <!--
      See the <a href="wms-capabilities.js" target="_blank">wms-capabilities.js source</a> to see how this is done.</p>
      -->
      <!-- ファイル修正 -->
      See the <a href="259-ol3ex.js" target="_blank">259-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">wms, capabilities, getcapabilities</div>
    </div>
    <div class="span8">
     <pre id="log"></pre>
    </div>
   </div>
  </div>
  <!--
  <script src="../resources/jquery.min.js" type="text/javascript"></script>
  <script src="../resources/example-behaviour.js" type="text/javascript"></script>
  -->
  <!-- ディレクトリ修正
   jQuery Minified版と
   example-behaviour.js(Examples用 JSコード[文字コードなど])
  -->
  <script src="v3.2.0/resources/jquery.min.js" type="text/javascript"></script>
  <script src="v3.2.0/resources/example-behaviour.js" type="text/javascript"></script>
  <!--
  <script src="loader.js?id=wms-capabilities" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=259-ol3ex" type="text/javascript"></script>
 </body>
</html>

2013年11月24日日曜日

22 - OpenLayers であきる野市の地図を表示 1 - マップファイルの設定

22-1 あきる野市のマップファイルの設定
基盤地図情報(あきる野市)の準備をするため nippon_bmi_akiruno.pgis.map を修正して WMS サーバの設定をします。

MAP
 NAME nippon_bmi_akiruno_pgis_map
---
 PROJECTION        # 投影法 (OpenLayers のため追加)
  "init=epsg:2451" #
 END               #
 WEB
  IMAGEPATH "/home/user/mapsite/ms_tmp/"
  IMAGEURL "/mapsite/ms_tmp/"
  METADATA # 追加
   "wms_title" "Nioopn BMI Akiruno Map WMS Server"
   "wms_onlineresource" "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map"
   "wms_srs" "EPSG:2451"
   "wms_enable_request" "*"
  END
 END
---
 LAYER
  NAME akiruno_kukaku
  GROUP akiruno_kukaku
  TYPE POLYGON
  STATUS ON
  CONNECTIONTYPE POSTGIS
  CONNECTION "dbname=nippon_bmi host=localhost user=user password=password"
  DATA "the_geom from akiruno_kukaku"
#  DATA "../mapdata/tokyo/akiruno/13228-20120305-AdmArea.shp"
  MINSCALEDENOM 500    # 不適当な縮尺で使用されないように。
  MAXSCALEDENOM 1000000
  LABELITEM "name"
  METADATA
   "wms_title" "Akiruno Kukaku Map WMS Layer"
   "wms_format" "image/png"
  END
  CLASS
   NAME "kukaku"
   STYLE
    COLOR 255 255 204
    OUTLINECOLOR 204 204 204
   END
   LABEL
    MINFEATURESIZE 40
    TYPE TRUETYPE
    FONT vl-gothic
    ENCODING UTF-8
    SIZE 8
   END
  END
 END
---
 LAYER
  NAME akiruno_kukakusen
  GROUP akiruno_kukakusen
  TYPE LINE
  STATUS ON
  CONNECTIONTYPE POSTGIS
  CONNECTION "dbname=nippon_bmi host=localhost user=user password=password"
  DATA "the_geom from akiruno_kukakusen"
#  DATA "../mapdata/tokyo/akiruno/13228-20120305-AdmBdry.shp"
  MINSCALEDENOM 500 # 不適当な縮尺で使用されないように。
  MAXSCALEDENOM 1000000
  METADATA
   "wms_title" "Akiruno Kukakusen Map WMS Layer"
   "wms_format" "image/png"
  END
  CLASS
   NAME "kukakusen"
   STYLE
    COLOR 204 204 204
   END
  END
 END
---



WMS 機能ドキュメントのチェック
端末(ターミナル)で次のようにコマンドを入力します。

wget -O nippon_bmi_akiruno_pgis_111.xml "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map&service=WMS&version=1.1.1&request=GetCapabilities"

nippon_bmi_akiruno_pgis_111.xml の内容をみてみます。
次のような警告が表示されました。

<!-- WARNING: Mandatory metadata '..._GROUP_TITLE' was missing in this context. -->

wms_group_title は、任意で設定します。

<!-- WARNING: Mandatory metadata '..._title' was missing in this context. -->

wms_title は、設定したいレイヤに記述します。

GetMap リクエストで画像を表示してみます。
Webブラウザのアドレサバーに次のように入力してEnterキーを押します。

http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map&service=WMS&version=1.1.1&request=GetMap&layers=akiruno_kukaku&srs=EPSG:2451&bbox=-63063.744614,-34495.938759,-45431.621385,-24289.584360&format=image/png&width=600&height=300


2013年11月23日土曜日

21 - OpenLayers で東京都の地図を表示 1 - マップファイルの設定

21-1 東京都のマップファイルの設定
国土数値情報(東京都のデータ)と基盤地図情報(あきる野市)を同じ地図上に表示しました。
単位が、度数(degree)とメートル(meter)のデータです。

最初に、国土数値情報(東京都のデータ)の準備をするため、「OpenLayers 10a-d unitsがddとmeterのレイヤ」を参考に、nippon_nlni_tokyo_pgis.map に WMS サーバの設定をします。

1 OpenLayers では地図を表示するのに、マップファイルに MAP オブジェクトの PROJECTION オブジェクトが必要です。
epsg:4326(PROJECTION オブジェクトでは epsg を小文字で設定)は、X/Yの値で扱われるれる緯度と経度で地図を説明する一般的な識別子です。
これは、MapServer と OpenLayers のデフォルトの投影法である正距円筒図法ですが、必ず設定します。

2 WMS サーバ機能を設定するのに、WEB オブジェクトの METADATA オブジェクトに、 "wms_title" と "wms_srs", "wms_enable_request"(以上必須), "wms_onlineresource"(推奨 GetCapabilities のために) を設定します。
「wms_enable_request」は、GetCapabilities, GetMap, GetFeatureInfo and GetLegendGraphic のリクエストを許可します。
"wms_srs" に、基盤地図情報のに合わせて "EPSG:2451" も設定します。
これによって、"wms_srs" の識別子が WMS を利用できるすべてのレイヤに設定されます。
3 レイヤを WMS で利用できるように、同じように、METADATA オブジェクトに、 "wms_title" を設定します。
レイヤを別の投影法で利用したいときは、個別に "wms_srs" を設定します。

MAP
 NAME nippon_nlni_tokyo_pgis_map
 STATUS ON
 SIZE 600 300
 EXTENT 138.85 35.4 140 35.975 # 諸島部を除いた範囲
 UNITS DD
 IMAGECOLOR 255 255 255
# IMAGETYPE PNG
 FONTSET "fonts.txt"

 PROJECTION # 投影法 (OpenLayers のため追加)<-1
   "init=epsg:4326"
 END
 WEB
  IMAGEPATH "/home/user/mapsite/ms_tmp/"
  IMAGEURL "/mapsite/ms_tmp/"
  METADATA
   "wms_title" "Nippon NLNI Tokyo Map WMS Server" # WMS サーバ設定<-2
   "wms_srs" "EPSG:2451 EPSG:4326" # 投影法<-2
   "wms_onlineresource" "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map&" # <-2
   "wms_enable_request" "*" # <-2
  END
 END
---
 LAYER
  NAME tokyo_kuiki
---
  METADATA
   "wms_title" "Tokyo Kuiki Map WMS Layer" # <-3
  END
---
 LAYER
  NAME tokyo_pf
---
  METADATA
   "wms_title" "Tokyo Public Facilities Map WMS Layer" # <-3
  END
---


GetCapabilities で WMS の情報を取得できます。
警告(<!-- WARNING:...)がありますが、今回は地図の表示に影響ありません。

wget -O nippon_nlni_tokyo_pgis.xml "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_pf_pgis.map&service=WMS&version=1.1.1&request=GetCapabilities"

user@debian:~/xml$ vim nippon_nlni_tokyo_pgis_111.xml
<?xml version='1.0' encoding="ISO-8859-1" standalone="no" ?>
<!DOCTYPE WMT_MS_Capabilities SYSTEM "http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd"
 [
 <!ELEMENT VendorSpecificCapabilities EMPTY>
 ]>  <!-- end of DOCTYPE declaration -->

<WMT_MS_Capabilities version="1.1.1">

<!-- MapServer version 6.0.1 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=CAIRO SUPPORTS=FREETYPE SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS=THREADS SUPPORTS=GEOS INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE -->

ここには、MapServer がサポートする機能が出力されています。
WMS がサポートされています。

---
  <Layer>
    <Name>nippon_nlni_tokyo_pgis_map</Name>
    <Title>Nioopn NLNI Tokyo Map WMS Server</Title>
    <Abstract>nippon_nlni_tokyo_pgis_map</Abstract>
    <SRS>EPSG:4326</SRS>
    <SRS>EPSG:2451</SRS>
    <LatLonBoundingBox minx="138.85" miny="35.4" maxx="140" maxy="35.975" />
    <BoundingBox SRS="EPSG:4326"
                minx="138.85" miny="35.4" maxx="140" maxy="35.975" />
    <Layer queryable="0" opaque="0" cascaded="0">
        <Name>tokyo_kuiki</Name>
        <Title>Tokyo Kuiki Map WMS Layer</Title>
        <SRS>EPSG:4326</SRS>
        <LatLonBoundingBox minx="-2.5e+07" miny="-2.5e+07" maxx="2.5e+07" maxy="2.5e+07" />
        <BoundingBox SRS="EPSG:4326"
                    minx="-2.5e+07" miny="-2.5e+07" maxx="2.5e+07" maxy="2.5e+07" />
        <Style>
          <Name>default</Name>
          <Title>default</Title>
          <LegendURL width="139" height="23">
             <Format>image/png</Format>
             <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&version=1.1.1&service=WMS&request=GetLegendGraphic&layer=tokyo_kuiki&format=image/png&STYLE=default"/>
          </LegendURL>
        </Style>
        <ScaleHint min="0.249451424214819" max="498.902848429637" />
    </Layer>
---

      <Name>tokyo_pf</Name>
<!-- WARNING: Mandatory metadata '..._GROUP_TITLE' was missing in this context. -->
      <Title>tokyo_pf</Title>
      <Abstract>tokyo_pf</Abstract>
        <Style>
          <Name>default</Name>
          <Title>default</Title>
          <LegendURL width="87" height="23">
             <Format>image/png; mode=24bit</Format>
             <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&version=1.1.1&service=WMS&request=GetLegendGraphic&layer=tokyo_pf&format=image/png; mode=24bit&STYLE=default"/>
          </LegendURL>
        </Style>
      <Layer queryable="0" opaque="0" cascaded="0">
        <Name>tokyo_pf</Name>
        <Title>Tokyo Public Facilities Map WMS Layer</Title>
        <SRS>EPSG:4326</SRS>
        <LatLonBoundingBox minx="-2.5e+07" miny="-2.5e+07" maxx="2.5e+07" maxy="2.5e+07" />
        <BoundingBox SRS="EPSG:4326"
                    minx="-2.5e+07" miny="-2.5e+07" maxx="2.5e+07" maxy="2.5e+07" />
        <Style>
          <Name>default</Name>
          <Title>default</Title>
          <LegendURL width="87" height="23">
             <Format>image/png</Format>
             <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&version=1.1.1&service=WMS&request=GetLegendGraphic&layer=tokyo_pf&format=image/png&STYLE=default"/>
          </LegendURL>
        </Style>
        <ScaleHint min="0.249451424214819" max="12.4725712107409" />
      </Layer>
    </Layer>
---

GetMap リクエストで画像を表示してみます。
Webブラウザのアドレサバーに次のように入力してEnterキーを押します。

http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&service=WMS&version=1.1.1&request=GetMap&layers=tokyo_kuiki&srs=EPSG:4326&bbox=138.85,35.4,140,35.975&format=image/png&width=600&height=300









///// 補足 /////
次のアドレスを Web ブラウザのアドレスバーに入力して Enter キーを押すと、最初、地図が表示されませんでした。

http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&service=WMS&version=1.1.1&request=GetMap&layers=tokyo_kuiki

「mapserv」ファイルが作成されます。そこには、次のように記述されています。

<?xml version='1.0' encoding="ISO-8859-1" standalone="no" ?> <!DOCTYPE ServiceExceptionReport SYSTEM "http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd"> <ServiceExceptionReport version="1.1.1"> <ServiceException> msWMSDispatch(): WMS server error. WMS request not enabled. Check wms/ows_enable_request settings. </ServiceException> </ServiceExceptionReport>
nippon_nlni_tokyo_pgis.map の WEB オブジェクトに次のように追加しました。
---
 WEB
  IMAGEPATH "/home/user/mapsite/ms_tmp/"
  IMAGEURL "/mapsite/ms_tmp/"
  METADATA
   "wms_title" "Nippon NLNI Tokyo Map WMS Server"
   "wms_srs" "EPSG:2451 EPSG:4326"
   "wms_onlineresource" "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map"
   "wms_enable_request" "*" #追加
  END
 END
---


地図を表示すると次のようにメッセージが作成されるので、アドレスを修正していきました。

msWMSLoadGetMapParams(): WMS server error. Missing required parameter SRS
 -> srs=epsg:4326
msWMSLoadGetMapParams(): WMS server error. Missing required parameter BBOX
 -> bbox=-138.85,35.4,140,35.975
msWMSLoadGetMapParams(): WMS server error. Missing required parameter FORMAT
 -> format=image/png
msWMSLoadGetMapParams(): WMS server error. Missing required parameter WIDTH
 -> width=600
msWMSLoadGetMapParams(): WMS server error. Missing required parameter HEIGHT -> height=300
///// ここまで /////