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

2014年10月22日水曜日

2 - ol3ex 21b - WFS example 2

OpenLayers 2 では、ドメインの違うサーバから WFS でデータを取得するのに、proxy.cgi ファイルを設定しました。OpenLayers 3 は、別の手順で取得します。
vector-wfs.js で、自分の GeoServer から WFS のデータを次のようにリクエストします。
var url = 'http://localhost:8080/geoserver/wfs?service=WFS&' +
 'version=1.1.0&request=GetFeature&typename=npn:akiruno_suiiki&' +
 'outputFormat=text/javascript&format_options=callback:loadFeatures' +
 '&srsname=EPSG:2451&bbox=' + extent.join(',') + ',EPSG:2451';

Geoserver に WFS をリクエストするとき、オプションを 「outputFormat=text/javascript」とすると、JSON形式で取得できます。

vector レイヤは表示されませんでした。
Firebug を起動して再表示すると、次のように表示されました。

データが、XML(GML)で送信されています。
Google で検索すると、「Geographic Information Systems Stack Exchange」の「GeoServer 2.3 how to enable jsonp(http://gis.stackexchange.com/questions/57494/geoserver-2-3-how-to-enable-jsonp)」に、

---
Add to this file: /tomcat/webapps/geoserver/WEB-INF/web.xml
<context-param>
 <param-name>ENABLE_JSONP</param-name>
 <param-value>true</param-value>
</context-param>
---

とあります。自分のサーバでは、

user@debian7-vmw:~$ su
パスワード:
root@debian7-vmw:/home/user# vim /etc/tomcat7/web.xml
---
 <context-param>
  <param-name>ENABLE_JSONP</param-name>
  <param-value>true</param-value>
 </context-param>

</web-app>
:wq

と、ファイルに追加し、tomcat7 を再起動します。

root@debian7-vmw:/home/user# /etc/init.d/tomcat7 restart
[ ok ] Stopping Tomcat servlet engine: tomcat7.
[ ok ] Starting Tomcat servlet engine: tomcat7.

Firebug に何も表示されませんが、地図にも表示されません。
Webブラウザのアドレスバーに次のように入力します。

http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature&typename=npn:akiruno_suiiki&outputFormat=text/javascript&format_options=callback:loadFeatures&srsname=EPSG:2451
loadFeatures({
 "type":"FeatureCollection",
 "features":[{
  "type":"Feature",
  "id":"akiruno_suiiki.1",
  "geometry":{
   "type":"MultiPolygon",
   "coordinates":[[[[-45875.83465282351,-29805.840956966127],
---
   [-45875.83465282351,-29805.840956966127]]]]},
  "geometry_name":"the_geom",
  "properties":{
   "id":"K12_1",
   "uuid":"fgoid:10-00200-11-6554-5598",
   "presences":2.0120305E7,
   "presencef":2.9991231E7,
   "finished":2.0120305E7,
   "orggilvl":"2500",
   "orgmdid":null,
   "category":"表示",
   "flag":"既存",
   "type":"湖池",
   "name":null}},
---

このままでは変換が必要ですが、「srsname=EPSG:3857」にすると座標が EPSG:3857 になります。

http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature&typename=npn:akiruno_suiiki&outputFormat=text/javascript&format_options=callback:loadFeatures&srsname=EPSG:3857
loadFeatures({
 "type":"FeatureCollection",
 "features":[{"type":"Feature",
 "id":"akiruno_suiiki.1",
 "geometry":{
  "type":"MultiPolygon",
  "coordinates":[[[[1.5509721608105533E7,4263571.24847886],
---
  [1.5509721608105533E7,4263571.24847886]]]]},
 "geometry_name":"the_geom",
 "properties":{
  "id":"K12_1",
  "uuid":"fgoid:10-00200-11-6554-5598",
  "presences":2.0120305E7,
  "presencef":2.9991231E7,
  "finished":2.0120305E7,
  "orggilvl":"2500",
  "orgmdid":null,
  "category":"表示",
  "flag":"既存",
  "type":"湖池",
  "name":null}},
---

「url」を次のようにすると地図が表示されました。
var url = 'http://localhost:8080/geoserver/wfs?service=WFS&' +
 'version=1.1.0&request=GetFeature&typename=npn:akiruno_suiiki&' +
 'outputFormat=text/javascript&format_options=callback:loadFeatures' +
 '&srsname=EPSG:3857&bbox=' + extent.join(',') + ',EPSG:3857';

「vector-wfs.js(221-ol3ex.js)」は、地図を表示するのに必要な javascript です。
「221-ol3ex.js」
var vectorSource = new ol.source.ServerVector({
/** ol.source.ServerVector
 * A vector source in one of the supported formats, using
 * a custom function to read in the data from a remote 
 * server.
 * サポートされている形式の一つのベクトルソースは、
 * カスタム関数を使用してリモートサーバからデータを読み取ります。
 * (ol3 APL)
 */
 format: new ol.format.GeoJSON(),
 /** ol.format.GeoJSON 
  * Feature format for reading and writing data 
  * in the GeoJSON format.
  * GeoJSON フォーマットのデータを読み書きするための
  * フィーチャフォーマット。(ol3 API)
  */
 loader: function(extent, resolution, projection) {
  /**var url = 'http://demo.opengeo.org/geoserver/wfs?service=WFS&' +
   *  'version=1.1.0&request=GetFeature&typename=osm:water_areas&' +
   *  'outputFormat=text/javascript&format_options=callback:loadFeatures' +
   *  '&srsname=EPSG:3857&bbox=' + extent.join(',') + ',EPSG:3857';
   */
  var url = 'http://localhost:8080/geoserver/wfs?service=WFS&' +
   'version=1.1.0&request=GetFeature&typename=npn:akiruno_suiiki&' +
   'outputFormat=text/javascript&format_options=callback:loadFeatures' +
   '&srsname=EPSG:3857&bbox=' + extent.join(',') + ',EPSG:3857';
   // outputFormat=text/javascript: JSONP 形式で返信
  $.ajax({
  /** $.ajax( [url] [, settings] )
   * 非同期HTTP通信(Ajax)を行い、データの取得・処理を行います。
   * [url] String リクエスト送信先のURL
   * [settings] Object Ajaxリクエストでのオプションを記述したオ
   * ブジェクト(jQuery)
   */
   url: url,
   dataType: 'jsonp'
   /** JSONP (JSON with Padding)
    * さまざまなドメインから、JSON データを持った JavaScript を
    * 動的に挿入することができます。
    */
  });
 },
 strategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({
 /** ol.loadingstrategy
  * Strategies for loading vector data.
  * ベクタデータをローディングするための方法。
  * createTile 
  * ol.loadingstrategy のメソッド
  * (ol3 API)
  */
 /** ol.tilegrid.XYZ
  * Set the grid pattern for sources accessing XYZ 
  * tiled-image servers.
  * XYZタイル画像サーバにアクセスするソースのグリッドパターンを
  * 設定します。
  * (ol3 API)
  */
  maxZoom: 19
 })),
 projection: 'EPSG:3857',
 attributions: [new ol.Attribution({
 /** ol.Attribution
  * An attribution for a layer source.
  * レイヤソースの属性(ol3 API)
  */
  html: '<a href="http://portal.cyberjapan.jp/help/termsofuse.html" target="_blank">' + 
   '国土地理院</a> 基盤地図情報'
 })],
});
var loadFeatures = function(response) {
 vectorSource.addFeatures(vectorSource.readFeatures(response));
 /** addFeatures
  * ol.source.GeoJSON (Static vector source in GeoJSON 
  * format[GeoJSONフォーマットの静的ベクトルソース])のメソッド
  */
 /** readFeatures
  * ol.format.GeoJSON  (Feature format for reading and 
  * writing data in the GeoJSON format. [GeoJSONフォーマットで
  * データを読み書きするための機能の形式。])のメソッド
  * Read all features from a GeoJSON source. 
  * GeoJSONソースからすべてのフィーチャをお読み込む。
  * Works with both Feature and FeatureCollection sources.
  * フィーチャおよびフィーチャコレクションソースの両方で動作。
  * (ol3 API)
  */
};
var vector = new ol.layer.Vector({
/** ol.layer.Vector 
 * Vector data that is rendered client-side. Note that any 
 * property set in the options is set as a ol.Object property
 * on the layer object; for example, setting title: 'My 
 * Title' in the options means that title is observable, and 
 * has get/set accessors.
 * クライアント側で描画されたベクタデータ。オプションで設定した任
 * 意のプロパティは、レイヤオブジェクトで ol.Object プロパティ
 * として設定されていることに注意してください。たとえば、オプショ
 * ンで、title:'My Title' を設定することは、タイトルは 
 * observable で、アクセサを取得/設定することを意味します。
 * (ol3 API)
 */
 source: vectorSource,
 style: new ol.style.Style({
 /** ol.style.Style 
  * Base class for vector feature rendering styles.
  * ベクタフィーチャがスタイルを描画するための基本クラス。
  * (ol3 API)
  */
  stroke: new ol.style.Stroke({
  /** ol.style.Stroke 
   * Set stroke style for vector features. 
   * Note that the defaults given are the Canvas defaults, 
   * which will be used if option is not defined. 
   * The get functions return whatever was entered in the 
   * options; they will not return the default.
   * ベクタフィーチャのためのストロークスタイルの設定。
   * デフォルトは、オプションが定義されていない場合に使用され
   * る Canvas のデフォルトを与えられることに注意してください。 
   * GET関数は、オプションで入力されたものはすべて返します。
   * それらはデフォルトを返しません。(ol3 API)
   */
   color: 'rgba(0, 0, 255, 1.0)',
   width: 2
  })
 })
});
var raster = new ol.layer.Tile({
/** ol.layer.Tile 
 * For layer sources that provide pre-rendered, tiled 
 * images in grids that are organized by zoom levels for 
 * specific resolutions. 
 * プリレンダリング(事前描画)を提供するレイヤソースのための、
 * 特定の解像度でのズームレベルによって編成されているグリッドの
 * タイルイメージ。(ol3 API)
 */
 source: new ol.source.BingMaps({
 /** ol.source.BingMaps
  * Layer source for Bing Maps tile data.
  * Bing Maps タイルデータのレイヤソース。(ol3 API)
  */
  imagerySet: 'Aerial',
  key: 'Ak-dzM4***' // 省略してます
 })
});
var map = new ol.Map({
 layers: [raster, vector],
 target: document.getElementById('map'),
 view: new ol.View({
  //center: [-8908887.277395891, 5381918.072437216]
  center: [15499413.571008531, 4264076.282950245],
  maxZoom: 19,
  zoom: 12
 })
});

2 - ol3ex 21a - WFS example 1

「WFS example(vector-wfs.html)」を参考に地図を表示してみます。

OGC(http://www.opengeospatial.org/) の 「OpenGIS Web Map Tile Service Implementation Standard(http://www.opengeospatial.org/standards/wmts)」には、次ように書かれています。
*****
The OGC Web Map Service allows a client to overlay map images for display served from multiple Web Map Services on the Internet.
OGC の ウェッブマップサービス(WMS)は、クライアントにインターネット上で複数のウェッブマップサービス(WMS)から提供される、表示するためのマップ画像をオーバーレイすることを可能にします。

In a similar fashion, the OGC Web Feature Service allows a client to retrieve and update geospatial data encoded in Geography Markup Language (GML) from multiple Web Feature Services.
同様に、OGC のウェッブフィーチャサービス(WFS)は、クライアントに、複数のウェッブフィーチャサービス(WFS)からジオグラフィマークアップラングエッジ(GML)でエンコードされた地理空間データを取得し、更新することを可能にします。

The requirements for a Web Feature Service are:
ウェブフィーチャサービスのための要件は次のとおりです。
1. The interfaces must be defined in XML.
インターフェイスは、XMLで定義する必要があります。
2. GML must be used to express features within the interface.
GMLは、インタフェース内の地物を表現するために使用されなければなりません。
3. At a minimum a WFS must be able to present features using GML.
最低限、WFS が GML を使用しての地物を提示することができなければなりません。
4. The predicate or filter language will be defined in XML and be derived from CQL as defined in the OpenGIS Catalogue Interface Implementation Specification.
OpenGIS Catalogue Interface Implementation Specification で定められた通り、述語型言語またはフィルタ言語は、XMLで定められ、CQLに由来します。
5. The datastore used to store geographic features should be opaque to client applications and their only view of the data should be through the WFS interface.
地理的特徴物を格納するために使用されるデータストアは、クライアント·アプリケーションに対して不透明であるべきであり、データの唯一のビューは、WFSインタフェースを介さなければなりません。
6.The use of a subset of XPath expressions for referencing properties.
プロパティを参照するためのXPath式のサブセットを使用します。
*****

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





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





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



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








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











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


「221-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.0.0/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>WFS 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.0.0/examples/"><img src="v3.0.0/resources/logo.png"> OpenLayers 3 Examples</a>
    </div>
   </div>
  </div>
  <div class="container-fluid">
   <div class="row-fluid">
    <div class="span12">
     <div id="map" class="map"></div>
    </div>
   </div>
   <div class="row-fluid">
    <div class="span12">
     <h4 id="title">WFS example</h4>
     <p id="shortdesc">Example of using WFS with a BBOX strategy.</p>
     <div id="docs">
<!--
      <p>See the <a href="vector-wfs.js" target="_blank">vector-wfs.js source</a> to see how this is done.</p>
-->
       <!-- ファイル修正 -->
      <p>See the <a href="221-ol3ex.js" target="_blank">221-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">vector, WFS, bbox, loading, server</div>
    </div>
   </div>
  </div>
<!--
  <script src="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.0.0/examples/jquery.min.js" type="text/javascript"></script>
  <script src="v3.0.0/resources/example-behaviour.js" type="text/javascript"></script>
<!--
  <script src="loader.js?id=vector-wfs" type="text/javascript"></script>
-->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=221-ol3ex" type="text/javascript"></script>

 </body>
</html>

2013年12月4日水曜日

28 - あきる野市の地図で属性のポップアップ表示(WFS)

WFS レイヤの属性のポップアップ表示
東京都の公共施設のレイヤ(tokyo_pf)の WFS レイヤの属性をポップアップ表示させる機能を追加します。

Geographic Information Systems の

How to collect data via WFS and Popup
http://gis.stackexchange.com/questions/34390/how-to-collect-data-via-wfs-and-popup

を参考に、WFS レイヤの属性をポップアップ表示します。

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







b 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「ol007-nippon_bmi_akiruno_pgis.html」をクリックして選択し、「OK」ボタンをクリックします。





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




d 「ウィザードを選択」ウィンドウで、「Web」(複数あるときは展開して探してください。)->「HTMLファイル」をクリックして選択し、「次へ」ボタンをクリックします。






e 「HTML」ウィンドウで「openlayersTokyoproj」をクリックして選択し、「ファイル名」を「ol008-nippon_bmi_akiruno_pgis.html」と入力し、「完了」ボタンをクリックします。







f 「ol007-nippon_bmi_akiruno_pgis.html」の内容をコピーして「ol008-nippon_bmi_akiruno_pgis.html」ファイルに貼り付けます。
g javascript の一部を次のように修正します。

---
 map.addControl(new OpenLayers.Control.LayerSwitcher());
 map.addControl(new OpenLayers.Control.MousePosition());
 map.zoomToMaxExtent();


 // ここから追加
 var select = new OpenLayers.Control.SelectFeature(layer4);
 map.addControl(select);
 select.activate();


 function onPopupClose(evt) {
  selectControl.unselect(selectedFeature);
 }


 layer4.events.on({
  featureselected: function(event) {
   var feature = event.feature;


   var content = '<h1>' + feature.attributes.p02_004 + '</h1>'
    + '<hr>'
    + feature.attributes.p02_001 + '<br />'
    + feature.attributes.p02_002 + '<br />'
    + feature.attributes.p02_003 + '<br />'
    + feature.attributes.p02_005 + '<br />'
    + feature.attributes.p02_006 + '<br />'
    + feature.attributes.p02_007;


   feature.popup = new OpenLayers.Popup.FramedCloud(
    "pop",
    feature.geometry.getBounds().getCenterLonLat(),
    null,
    content,
    null,
    true
   );
   map.addPopup(feature.popup);
  },
  featureunselected: function(event) {
   var feature = event.feature;
   map.removePopup(feature.popup);
   feature.popup.destroy();
   feature.popup = null;
  }
 });
}
</script>
</head>
<body onload="init()">

---

ブラウザのアドレスバーに

http://192.168.1.200/mapsite/openlayersTokyoproj/ol008-nippon_bmi_akiruno_pgis.html

と入力して Enter キーを押します。
表示しない倍率で表示させてみました。

文字化けしてしまいました。
MapServer の WFS のエンコードが、ISO-8859-1 なのが理由です。




Javascript で文字化けを修正できなかった(私のスキルの問題)ので、MapServer の WFS サーバにエンコード「UTF-8」を設定しました。

nob61@debian7-vmw:~/mapfile$ vim nippon_nlni_tokyo_pgis.map

---
 WEB
   IMAGEPATH "/home/user/mapsite/ms_tmp/"
   IMAGEURL "/mapsite/ms_tmp/"
   METADATA
     "wms_title" "Nioopn NLNI Tokyo Map WMS Server" # WMS サーバ設定
     "wms_onlineresource" "http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&"
     "wms_srs" "EPSG 2451 EPSG:4326"
     "wms_enable_request" "*"
     "wfs_title" "Nippon NLNI Tokyo Map WFS Server" # WFS サーバ設定
     "wfs_onlineresource" "http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&"
     "wfs_srs" "EPSG:4326"
     "wfs_enable_request" "*"
     "wfs_encoding" "UTF-8" # 追加
   END
---


ブラウザのアドレスバーに

http://192.168.1.200/mapsite/openlayersTokyoproj/ol008-nippon_bmi_akiruno_pgis.html

と入力して Enter キーを押します。










GeoServer の WFS のエンコードは、UTF-8 なので日本語が表示されます。

2013年12月2日月曜日

27 - あきる野市の地図にスタイルを設定(WFS) 2 - 公共施設の色分け(Point)

27-2 公共施設の色分け(Point)

OpenLayers Styling ページ
http://docs.openlayers.org/library/feature_styling.html

の「Custom Rules」の項目に、
ある値に対する大小や文字列の照合を基本にした応用スタイルルールを作成できる、とあります。
LESS_THAN、GREATER_THAN、EQUAL_TO を使用したフィルタの例を参考に、「ol006-nippon_bmi_akiruno_pgis.html」のコードを編集します。

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







b 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「ol006-nippon_bmi_akiruno_pgis.html」をクリックして選択し、「OK」ボタンをクリックします。





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




d 「ウィザードを選択」ウィンドウで、「Web」(複数あるときは展開して探してください。)->「HTMLファイル」をクリックして選択し、「次へ」ボタンをクリックします。






e 「HTML」ウィンドウで「openlayersTokyoproj」をクリックして選択し、「ファイル名」を「ol007-nippon_bmi_akiruno_pgis.html」と入力し、「完了」ボタンをクリックします。







f 「ol006-nippon_bmi_akiruno_pgis.html」の内容をコピーして「ol007-nippon_bmi_akiruno_pgis.html」ファイルに貼り付けます。
g javascript の一部を次のように修正します。
---
/*
var style_publicFacilities = new OpenLayers.Style({
 fillColor: '#ff9999',
 fillOpacity: '0.5',
 strokeColor: '#ff3333',
 pointRadius: 6
});
*/
var style_publicFacilities = new OpenLayers.Style();
var style_lightgreen = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 3
 }),
 symbolizer: {
  fillColor: "#99ff99",
  fillOpacity: 0.5,
  strokeColor: "#33ff33",
  pointRadius: 6
 }
});
var style_lightblue = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 11,
 }),
 symbolizer: {
  fillColor: "#9999ff",
  fillOpacity: 0.5,
  strokeColor: "#3333ff",
  pointRadius: 6
 }
var style_lightred = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 12,
 }),
 symbolizer: {
  fillColor: "#ff9999",
  fillOpacity: 0.5,
  strokeColor: "#ff3333",
  pointRadius: 6
 }
});
var style_lightyellow = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 13,
 }),
 symbolizer: {
  fillColor: "#ffff99",
  fillOpacity: 0.5,
  strokeColor: "#ffff33",
  pointRadius: 6
 }
});
var style_lightsyan = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 14,
 }),
 symbolizer: {
  fillColor: "#99ffff",
  fillOpacity: 0.5,
  strokeColor: "#33ffff",
  pointRadius: 6
 }
});
var style_lightmagenta = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 15,
 }),
 symbolizer: {
  fillColor: "#ff99ff",
  fillOpacity: 0.5,
  strokeColor: "#ff33ff",
  pointRadius: 6
 }
});
var style_green = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 16,
 }),
 symbolizer: {
  fillColor: "#33ff33",
  fillOpacity: 0.5,
  strokeColor: "#00ff00",
  pointRadius: 6
 }
});
var style_orange = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 17,
 }),
 symbolizer: {
  fillColor: "#ff9933",
  fillOpacity: 0.5,
  strokeColor: "#ff6600",
  pointRadius: 6
 }
});
var style_red = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 18,
 }),
 symbolizer: {
  fillColor: "#ff0000",
  fillOpacity: 0.5,
  strokeColor: "#ff0000",
  pointRadius: 6
 }
});
var style_yellow = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 19,
 }),
 symbolizer: {
  fillColor: "#ffff00",
  fillOpacity: 0.5,
  strokeColor: "#ff9933",
  pointRadius: 6
 }
});
var style_grey = new OpenLayers.Rule({
 filter: new OpenLayers.Filter.Comparison({
  type: OpenLayers.Filter.Comparison.EQUAL_TO,
  property: "p02_002",
  value: 9,
 }),
 symbolizer: {
  fillColor: "#999999",
  fillOpacity: 0.5,
  strokeColor: "#999999",
  pointRadius: 6
 }
});
style_publicFacilities.addRules([style_lightgreen,
 style_lightblue, style_lightred, style_lightyellow,
 style_lightsyan, style_lightmagenta, style_green,
 style_orange, style_red, style_yellow, style_grey]);
layer4 = new OpenLayers.Layer.Vector( "Tokyo Public Facilities Features",{
---
表示しない倍率で表示させてみました。










コードを次のようにもかけます。
Boundless
Introduction to OpenLayers
4.4. Understanding Style
http://workshops.boundlessgeo.com/openlayers-intro/vector/style-intro.html
より
---
var style_publicFacilities = new OpenLayers.Style({
// "rules:" 以下のルールに当てはまらないとき(「その他」のスタイル grey)
 fillColor: '#999999',
 fillOpacity: '0.5',
 strokeColor: '#999999',
 pointRadius: 6
 },{
 rules: [
// var style_lightgreen = new OpenLayers.Rule({
// 各スタイルでここを削除
  new OpenLayers.Rule({
   filter: new OpenLayers.Filter.Comparison({
    type: OpenLayers.Filter.Comparison.EQUAL_TO,
    property: "p02_002",
    value: 3
   }),
   symbolizer: {
    fillColor: "#99ff99",
    fillOpacity: 0.5,
    strokeColor: "#33ff33",
    pointRadius: 6
   }
  }),

// var style_lightblue = new OpenLayers.Rule({
  new OpenLayers.Rule({
   filter: new OpenLayers.Filter.Comparison({
   type: OpenLayers.Filter.Comparison.EQUAL_TO,
   property: "p02_002",
   value: 11,
  }),
---
/* スタイル grey (「その他」)のルールは削除   
  var style_grey = new OpenLayers.Rule({
   filter: new OpenLayers.Filter.Comparison({
   type: OpenLayers.Filter.Comparison.EQUAL_TO,
   property: "p02_002",
   value: 9,
  }),
  symbolizer: {
   fillColor: "#999999",
   fillOpacity: 0.5,
   strokeColor: "#999999",
   pointRadius: 6
  }
 }),

 style_publicFacilities.addRules([style_lightgreen,
  style_lightblue, style_lightred, style_lightyellow,
  style_lightsyan, style_lightmagenta, style_green,
  style_orange, style_red, style_yellow, style_grey]);
*/

  new OpenLayers.Rule({elsefilter: true})
 ]
});
  
layer4 = new OpenLayers.Layer.Vector( "Tokyo Public Facilities Features",{
---

27 - あきる野市の地図にスタイルを設定(WFS) 1 - OpenLayers のスタイル設定

27-1 OpenLayers でスタイルを設定

OpenLayers Styling ページ
http://docs.openlayers.org/library/feature_styling.html

を参考にスタイルを設定します。
「Style Classes」の項目に、スタイル情報が次の3つのうちの1つの資源から設定できるとあります。

●"シンボライザ ハッシュ" をフィーチャに直接設定。一般的ではないが、kml コンテンツのように、フィーチャレベルでスタイル情報を埋め込んだリモートデータをパースするとき作成。
●"シンボライザ ハッシュ" を layer.style としてレイヤに設定。
●Style または StyleMap オブジェクトを layer.styleMap としてレイヤに設定。

「StyleMap」の項目に、StyleMap の構成があります。

new OpenLayers.StyleMap(s);

"s" は、「Attribute Replacement Syntax」項目にある
var s = new OpenLayers.Style({
 'pointRadius': 10,
 'externalGraphic': '${thumbnail}'
});

ですが、'${thumbnail}' はわかりやすく画像のパスでもOKです。
"s" を直接記述する方法が次に示されています。
new OpenLayers.StyleMap({
 'pointRadius': 10,
 'externalGraphic': '${thumbnail}'
});

「Using Style Objects」の項目に、レイヤに設定するときの構成があります。
var styleMap = new OpenLayers.StyleMap({
 pointRadius: 10,
 externalGraphic: '${thumbnail}'
});
var l = new OpenLayers.Layer.Vector("Vector Layer",
 {styleMap: styleMap});

あきる野市の地図に設定してみます。
「Style Properties」の項目に、設定項目があります。

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




b 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「ol004-nippon_bmi_akiruno_pgis.html」をクリックして選択し、「OK」ボタンをクリックします。





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




d 「ウィザードを選択」ウィンドウで、「Web」(複数あるときは展開して探してください。)->「HTMLファイル」をクリックして選択し、「次へ」ボタンをクリックします。






e 「HTML」ウィンドウで「openlayersTokyoproj」をクリックして選択し、「ファイル名」を「ol006-nippon_bmi_akiruno_pgis.html」と入力し、「完了」ボタンをクリックします。







f 「ol004-nippon_bmi_akiruno_pgis.html」の内容をコピーして「ol006-nippon_bmi_akiruno_pgis.html」ファイルに貼り付けます。
g javascript の一部を次のように修正します。

---
 var style_kukaku = new OpenLayers.Style({
  fillColor: '#ffff99', // 塗りつぶし色
  fillOpacity: '0.5', // 透過度
  strokeColor: '#ffff33' // 外周色
 });

 layer1 = new OpenLayers.Layer.Vector("Akiruno Kukaku Features", {
  strategies: [new OpenLayers.Strategy.BBOX()],
  protocol: new OpenLayers.Protocol.WFS({
   url: "http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map",
//   featureNS : "http://www.myhome.net/",
   featureType: "akiruno_kukaku"
//   geometryName: "the_geom",
//   featurePrefix: "npn",
//   srsName: "EPSG:2451",
//   version: "1.0.0"
  }),
  styleMap: new OpenLayers.StyleMap(style_kukaku)
 });

 var style_kenchiku = new OpenLayers.Style({
  fillColor: '#cccc66',
  fillOpacity: '0.5',
  strokeColor: '#cccc33',
  strokeWidth: '0.5' // 外周太さ
 });

 layer2 = new OpenLayers.Layer.Vector( "Akiruno Kenchiku Features", {
  strategies: [new OpenLayers.Strategy.BBOX()],
  protocol: new OpenLayers.Protocol.WFS({
   url: "http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map",
   featureType: "akiruno_kenchiku"
  }),
  styleMap: new OpenLayers.StyleMap(style_kukaku)
 });
 var style_kuiki = new OpenLayers.Style({
  fillColor: '#99ff99',
  fillOpacity: '0.5',
  strokeColor: '#33ff33'
 });

 layer3 = new OpenLayers.Layer.Vector("Tokyo Kuiki Features", {
  strategies: [new OpenLayers.Strategy.BBOX()],
  projection: new OpenLayers.Projection("EPSG:4326"),
  protocol: new OpenLayers.Protocol.WFS({
   url: "http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis20.map",
   featureType: "tokyo_kuiki"
  }),
  styleMap: new OpenLayers.StyleMap(style_kuiki)
 });
 var style_publicFacilities = new OpenLayers.Style({
  fillColor: '#ff9999',
  fillOpacity: '0.5',
  strokeColor: '#ff3333',
  pointRadius: 6 // 大きさ
 });

 layer4 = new OpenLayers.Layer.Vector( "Tokyo Public Facilities Features",{
  strategies: [new OpenLayers.Strategy.BBOX()],
  projection: new OpenLayers.Projection("EPSG:4326"),
  protocol: new OpenLayers.Protocol.WFS({
   url: "http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis20.map",
   featureType: "tokyo_pf"
  }),
  styleMap: new OpenLayers.StyleMap(style_kukaku)
 });

/*
 1 「建物」と「公共施設」は表示に時間がかかるので表示倍率が高いときだけ表示。
 Geographic Information Systems
 Different level of detail(layers) on different zoom level at OpenLayers map
 http://gis.stackexchange.com/questions/24987/different-level-of-detaillayers-on-different-zoom-level-at-openlayers-map
 より
*/
 layer2.setVisibility(false);  layer4.setVisibility(false);
 map.addLayers([layer0, layer3, layer1, layer2, layer4]);

//2 「建物」と「公共施設」は表示に時間がかかるので表示倍率が高いときだけ表示。
 map.events.register('zoomend', this, function (event) {
  var zLevel = map.getZoom();     
  if( zLevel < 4)
  {
   layer2.setVisibility(false);
   layer4.setVisibility(false);
  }
  if( zLevel >= 4)
  {
   layer2.setVisibility(true);
   layer4.setVisibility(true);
  }
 });
 map.addControl(new OpenLayers.Control.LayerSwitcher());
 map.addControl(new OpenLayers.Control.MousePosition());
 map.zoomToMaxExtent();
}
---

ブラウザのアドレスバーに

http://192.168.1.200/mapsite/openlayersTokyoproj/ol006-nippon_bmi_akiruno_pgis.html

と入力して Enter キーを押します。








次のようなメッセージが表示されたら、「処理を続行」ボタンをクリックします。

2013年11月26日火曜日

24 - あきる野市の地図をWFSで表示 2 - WFS サーバを設定(あきる野市)

24-2 あきる野市のマップファイルに WFS サーバを設定
東京都のマップファイルと同じように、あきる野市のマップファイルに WFS サーバを設定します。

user@debian7-vmw:~/mapfile$ vim nippon_bmi_akiruno_pgis.map

MAP
 NAME nippon_bmi_akiruno_pgis_map
 STATUS ON
 SIZE 600 300
 EXTENT -63063.744614 -34495.938759 -45431.621385 -24289.584360
 UNITS meters
 IMAGECOLOR 255 255 255
 FONTSET "fonts.txt"

 PROJECTION # 投影法 (OpenLayers のため追加)
  "init=epsg:2451"
 END

 WEB
  IMAGEPATH "/home/user/mapsite/ms_tmp/"
  IMAGEURL "/mapsite/ms_tmp/"
  METADATA
   "wms_title" "Nippon 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 EPSG:2456 EPSG:4326"
   "wms_enable_request" "*"
   "wfs_title" "Nippon BMI Akiruno Map WFS Server" # WFS サーバ設定
   "wfs_onlineresource" "http://192.168.10.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map&"
   "wfs_srs" "EPSG:2451"
   "wfs_enable_request" "*"
  END
 END
---
 LAYER
  NAME akiruno_kukaku
  GROUP akiruno_kukaku
  TYPE POLYGON
  STATUS ON
---
  METADATA
   "wms_title" "Akiruno Kukaku Map WMS Layer"
   "wms_format" "image/png"
   "wms_srs" "EPSG:2451 EPSG:4326"
   "wfs_title" "Akiruno Kukaku Map WFS Layer"
   "wfs_srs" "EPSG:2451 EPSG:4326"
   "gml_include_items" "all"
   "gml_featuredid" "gid"
  END
---

nippon_bmi_akiruno_pgis.map の GetCapabilities の出力結果

user@debian7-vmw:~/ドキュメント$ wget -O bmi_akiruno_wfs_gc.xml "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map&service=wfs&version=1.0.0&request=GetCapabilities"
user@debian7-vmw:~/ドキュメント$ vim bmi_akiruno_wfs_gc.xml
<?xml version='1.0' encoding="ISO-8859-1" ?>
<WFS_Capabilities
 version="1.0.0"
 updateSequence="0"
 xmlns="http://www.opengis.net/wfs"
 xmlns:ogc="http://www.opengis.net/ogc"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd">

<!-- 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 -->

<Service>
 <Name>MapServer WFS</Name>
 <Title>Nippon BMI Akiruno Map WFS Server</Title>
 <OnlineResource>http://192.168.10.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map&</OnlineResource>
</Service>
---
<FeatureTypeList>
 <Operations>
  <Query/>
 </Operations>
 <FeatureType>
  <Name>akiruno_kukaku</Name>
  <Title>Akiruno Kukaku Map WFS Layer</Title>
  <SRS>EPSG:2451</SRS>
  <LatLongBoundingBox minx="-2.5e+07" miny="-2.5e+07" maxx="2.5e+07" maxy="2.5e+07" />
 </FeatureType>
---

1 「<WFS_Capabilities...」WFS Capabiities の名前空間
2 「<!-- MapServer version 6.0.1...」MapServer の動作している機能
3 「<Service>...」WFS の設定
4 「<FeatureTypeList>...」各レイヤの設定

nippon_bmi_akiruno_pgis.map の getfeature の出力結果

user@debian7-vmw:~/ドキュメント$ wget -O bmi_akiruno_kukaku_wfs_gf.xml "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map&service=wfs&version=1.0.0&request=GetFeature&TYPENAME=akiruno_kukaku"
<?xml version='1.0' encoding="ISO-8859-1" ?>
<wfs:FeatureCollection
 xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
 xmlns:wfs="http://www.opengis.net/wfs"
 xmlns:gml="http://www.opengis.net/gml"
 xmlns:ogc="http://www.opengis.net/ogc"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
  http://mapserver.gis.umn.edu/mapserver
  http://192.168.10.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_bmi_akiruno_pgis.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=akiruno_kukaku&OUTPUTFORMAT=XMLSCHEMA">
 <gml:boundedBy>
  <gml:Box srsName="EPSG:2451">
   <gml:coordinates>-63063.744614,-34495.938759 -45431.621385,-24289.584360</gml:coordinates>
  </gml:Box>
 </gml:boundedBy>
 <gml:featureMember>
  <ms:akiruno_kukaku fid="akiruno_kukaku.1">
   <gml:boundedBy>
    <gml:Box srsName="EPSG:2451">
     <gml:coordinates>-63063.744614,-34495.938759 -45431.621385,-24289.584360</gml:coordinates>
    </gml:Box>
   </gml:boundedBy>
   <ms:msGeometry>
    <gml:Polygon srsName="EPSG:2451">
     <gml:outerBoundaryIs>
      <gml:LinearRing>
       <gml:coordinates>-63063.744614,-25263.387051
---
      </gml:LinearRing>
     </gml:outerBoundaryIs>
    </gml:Polygon>
   </ms:msGeometry>
   <ms:gid>1</ms:gid>
   <ms:id>K4_1</ms:id>
   <ms:uuid>fgoid:10-00200-11-6572-94188</ms:uuid>
   <ms:presences>20120305</ms:presences>
   <ms:presencef>29991231</ms:presencef>
   <ms:finished>20120305</ms:finished>
   <ms:orggilvl>2500</ms:orggilvl>
   <ms:orgmdid></ms:orgmdid>
   <ms:category>表示</ms:category>
   <ms:flag>既存</ms:flag>
   <ms:type>郡市・東京都の区</ms:type>
   <ms:name>あきる野市</ms:name>
   <ms:code>13228</ms:code>
  </ms:akiruno_kukaku>
 </gml:featureMember>
---

1 「<wfs:FeatureCollection...」WFS FeatureCollection の名前空間
2 以下、地物のデータ

24 - あきる野市の地図をWFSで表示 1 - WFS サーバを設定(東京都)

24-1 東京都のマップファイルに WFS サーバを設定
WFS を利用して地図に属性を表示します。
WFS(Web Feature Service)は、座標や属性など、実際の地物のデータを配信します。

1 WFS サーバ機能を設定するのに、WEB オブジェクトの METADATA オブジェクトに、 "wfs_title"(必須)と "wfs_srs", "wfs_enable_request", "wfs_onlineresource"(以上推奨) を設定します。
"wfs_enable_request" は、GetCapabilities, GetFeature and  DescribeFeatureType のリクエストを許可します。
"wfs_srs" に、基盤地図情報のに合わせて "EPSG:2451" も設定します。
これによって、"wfs_srs" の識別子が WFS を利用できるすべてのレイヤに設定されます。
2 レイヤを WFS で利用できるように、同じように、METADATA オブジェクトに、 "wfs_title"、"wfs_srs"、"gml_featureid"、"gml_include_items" を設定します。
"gml_featureid" は、WFS データの属性の中でユニーク(唯一)なものを設定します。
"gml_include_items" は、配信する属性を決められます。設定は必須となっていませんが、しておいたほうがいいようです。

user@debian7-vmw:~/mapfile$ vim nippon_nlni_tokyo_pgis.map

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 のため追加)
  "init=epsg:4326"
 END
 
 WEB
  IMAGEPATH "/home/user/mapsite/ms_tmp/"
  IMAGEURL "/mapsite/ms_tmp/"
  METADATA
   "wms_title" "Nioopn NLNI Tokyo Map WMS Server"
   "wms_onlineresource" "http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&"
   "wms_srs" "EPSG 2451 EPSG:4326"
   "wms_enable_request" "*"
   "wfs_title" "Nippon NLNI Tokyo Map WFS Server" # <-1 ここから追加
   "wfs_onlineresource" "http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&"
   "wfs_srs" "EPSG:4326"
   "wfs_enable_request" "*"
  END
 END
---
 LAYER
  NAME tokyo_kuiki
  TYPE POLYGON
  STATUS ON
#  DUMP TRUE (ver.6より非推奨)
---
  METADATA
   "wms_title" "Tokyo Kuiki Map WMS Layer"
   "wms_srs" "EPSG:2451 EPSG:4326"
   "wfs_title" "Tokyo Kuiki Map WFS Layer" # <-2 ここから追加
   "wfs_srs" "EPSG:4326"
   "gml_featureid" "gid"
   "gml_include_items" "all"
  END
---
 LAYER
  NAME tokyo_pf
  GROUP tokyo_pf
  TYPE POINT
  STATUS ON
---
  METADATA
   "wms_title" "Tokyo Public Facilities Map WMS Layer"
   "wms_srs" "EPSG:2451 EPSG:4326"
   "wfs_title" "Tokyo Public Facilities Map WFS Layer" # <-2 ここから追加
   "wfs_srs" "EPSG:4326"
   "gml_featureid" "gid"
   "gml_include_items" "all"
  END
---

nippon_nlni_tokyo_pgis.map の WFS GetCapabilities の出力結果。

user@debian7-vmw:~/ドキュメント$ wget -O nlni_tokyo_wfs_gc.xml "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&service=wfs&version=1.0.0&request=GetCapabilities"
user@debian7-vmw:~/ドキュメント$ vim nlni_tokyo_wfs_gc.xml
<?xml version='1.0' encoding="ISO-8859-1" ?>
<WFS_Capabilities
 version="1.0.0"
 updateSequence="0"
 xmlns="http://www.opengis.net/wfs"
 xmlns:ogc="http://www.opengis.net/ogc"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd">

<!-- 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 -->

<Service>
 <Name>MapServer WFS</Name>
 <Title>Nippon NLNI Tokyo Map WFS Server</Title>
 <OnlineResource>http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&</OnlineResource>
</Service>
---
<FeatureTypeList>
 <Operations>
  <Query/>
 </Operations>
  <FeatureType>
   <Name>tokyo_kuiki</Name>
   <Title>Tokyo Kuiki Map WMS Layer</Title>
   <SRS>EPSG:4326</SRS>
   <LatLongBoundingBox minx="-2.5e+07" miny="-2.5e+07" maxx="2.5e+07" maxy="2.5e+07" />
  </FeatureType>
  <FeatureType>
   <Name>tokyo_pf</Name>
   <Title>Tokyo Public Facilities Map WFS Layer</Title>
   <SRS>EPSG:4326</SRS>
   <LatLongBoundingBox minx="-2.5e+07" miny="-2.5e+07" maxx="2.5e+07" maxy="2.5e+07" />
  </FeatureType>
---

1 「<WFS_Capabilities...」WFS Capabiities の名前空間
2 「<!-- MapServer version 6.0.1...」MapServer の動作している機能
3 「<Service>...」WFS の設定
4 「<FeatureTypeList>...」各レイヤの設定

nippon_nlni_tokyo_pgis.map の WFS GetFeature の出力結果。

user@debian7-vmw:~/ドキュメント$ wget -O nlni_tokyo_pf_wfs_gf.xml "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&service=wfs&version=1.0.0&request=GetFeature&TYPENAME=tokyo_pf"
<?xml version='1.0' encoding="ISO-8859-1" ?>
<wfs:FeatureCollection
 xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
 xmlns:wfs="http://www.opengis.net/wfs"
 xmlns:gml="http://www.opengis.net/gml"
 xmlns:ogc="http://www.opengis.net/ogc"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
  http://mapserver.gis.umn.edu/mapserver
  http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=tokyo_pf&OUTPUTFORMAT=XMLSCHEMA">
 <gml:boundedBy>
  <gml:Box srsName="EPSG:4326">
   <gml:coordinates>139.015694,26.640098 142.203778,35.841866</gml:coordinates>
  </gml:Box>
 </gml:boundedBy>
 <gml:featureMember>
  <ms:tokyo_pf fid="tokyo_pf.1">
   <gml:boundedBy>
    <gml:Box srsName="EPSG:4326">
     <gml:coordinates>139.734103,35.681014 139.734103,35.681014</gml:coordinates>
    </gml:Box>
   </gml:boundedBy>
   <ms:msGeometry>
    <gml:Point srsName="EPSG:4326">
     <gml:coordinates>139.734103,35.681014</gml:coordinates>
    </gml:Point>
   </ms:msGeometry>
   <ms:gid>1</ms:gid>
    <ms:p02_001>13101</ms:p02_001>
    <ms:p02_002>3</ms:p02_002>
    <ms:p02_003>03001</ms:p02_003>
    <ms:p02_004>ニューオータニ美術館</ms:p02_004>
    <ms:p02_005>紀尾井町4-1</ms:p02_005>
    <ms:p02_006>4</ms:p02_006>
    <ms:p02_007>数値地図画像</ms:p02_007>
   </ms:tokyo_pf>
  </gml:featureMember>
---

1 「<wfs:FeatureCollection...」WFS FeatureCollection の名前空間
2 以下、地物のデータ

2010年6月8日火曜日

OpenLayers 56b Snap/Split and Persist via WFS - Snap と Split を WFS で保存 2

HTML ファイルの作成

HTML ファイルを新規作成します。
「openlayersTokyoproj」 を右クリックして 新規 -> HTML ファイル をクリック。
「HTML ファイル」ウィンドウの「ファイル名(任意:openlayers_wfs-snap-split.html)」に入力して「完了」ボタンをクリック。
「charset」を「utf-8」にします。
「examples」の「wfs-snap-split.html」の内容をコピーして新規作成したファイルに貼り付けます。

コードの修正とちょっと解説します。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>OpenLayers56 Snap/Split and Persist via WFS</title>
<!-- OpenLayers ライブラリ -->
<script src="./lib/Firebug/firebug.js"></script>
<script src="./lib/OpenLayers.js"></script>

<!-- Proj4js ライブラリ -->
<script type="text/javascript" src="./lib/proj4js/lib/proj4js-compressed.js"></script>
<script type="text/javascript" src="./lib/proj4js/lib/projCode/tmerc.js"></script>
<script type="text/javascript" src="./lib/proj4js/lib/defs/EPSG2456.js"></script>

<!-- スタイルシート -->
<link rel="stylesheet" href="./theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="./examples/style.css" type="text/css" />


<!-- Editing Tool Bar スタイルシート -->
<style>
.customEditingToolbar {
float: right;
right: 0px;
height: 30px;
width: 200px;
}
.customEditingToolbar div {
float: right;
margin: 5px;
width: 24px;
height: 24px;
}
.olControlNavigationItemActive {
background-image: url("./theme/default/img/editing_tool_bar.png"); /* 修正 */
background-repeat: no-repeat;
background-position: -103px -23px;
}
.olControlNavigationItemInactive {
background-image: url("./theme/default/img/editing_tool_bar.png"); /* 修正 */
background-repeat: no-repeat;
background-position: -103px -0px;
}
.olControlDrawFeaturePointItemInactive {
background-image: url("./theme/default/img/editing_tool_bar.png"); /* 修正 */
background-repeat: no-repeat;
background-position: -77px 0px;
}
.olControlDrawFeaturePointItemActive {
background-image: url("./theme/default/img/editing_tool_bar.png"); /* 修正 */
background-repeat: no-repeat;
background-position: -77px -23px;
}
.olControlModifyFeatureItemActive {
background-image: url(./theme/default/img/move_feature_on.png); /* 修正 */
background-repeat: no-repeat;
background-position: 0px 1px;
}
.olControlModifyFeatureItemInactive {
background-image: url(./theme/default/img/move_feature_off.png); /* 修正 */
background-repeat: no-repeat;
background-position: 0px 1px;
}
.olControlDeleteFeatureItemActive {
background-image: url(./theme/default/img/remove_point_on.png); /* 修正 */
background-repeat: no-repeat;
background-position: 0px 1px;
}
.olControlDeleteFeatureItemInactive {
background-image: url(./theme/default/img/remove_point_off.png); /* 修正 */
background-repeat: no-repeat;
background-position: 0px 1px;
}
</style>


<script type="text/javascript">
var map, wfs;

var DeleteFeature = OpenLayers.Class(OpenLayers.Control, {
initialize: function(layer, options) {
OpenLayers.Control.prototype.initialize.apply(this, [options]);
this.layer = layer;
this.handler = new OpenLayers.Handler.Feature(
this, layer, {click: this.clickFeature}
);
},
clickFeature: function(feature) {
// if feature doesn't have a fid, destroy it
if(feature.fid == undefined) {
this.layer.destroyFeatures([feature]);
} else {
feature.state = OpenLayers.State.DELETE;
this.layer.events.triggerEvent("afterfeaturemodified", {feature: feature});
feature.renderIntent = "select";
this.layer.drawFeature(feature);
}
},
setMap: function(map) {
this.handler.setMap(map);
OpenLayers.Control.prototype.setMap.apply(this, arguments);
},
CLASS_NAME: "OpenLayers.Control.DeleteFeature"
});


function init() {
OpenLayers.ProxyHost= "/cgi-bin/proxy.cgi?url="; // 修正
map = new OpenLayers.Map('map', {
maxResolution: 156543.03390625,
restrictedExtent: new OpenLayers.Bounds(15518513, 4258113, 15518513, 4265113),// 表示範囲 東京駅周辺に変更
maxExtent: new OpenLayers.Bounds(-2.003750834E7,-2.003750834E7,2.003750834E7,2.003750834E7),// 世界全図
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"), // 追加
controls: [
new OpenLayers.Control.PanZoom()
]
});


// Open Street Map レイヤ
var wms = new OpenLayers.Layer.WMS("Base Layer",
"http://demo.opengeo.org/geoserver_openstreetmap/gwc/service/wms",
{
layers: 'openstreetmap',
format: 'image/png'
});

// 描画したフィーチャのスタイル
var styles = new OpenLayers.StyleMap({
"default": new OpenLayers.Style(null, {
rules: [
new OpenLayers.Rule({
symbolizer: {
"Point": {
pointRadius: 5,
graphicName: "square",
fillColor: "white",
fillOpacity: 0.25,
strokeWidth: 1,
strokeOpacity: 1,
strokeColor: "#333333"
},
"Line": {
strokeWidth: 3,
strokeOpacity: 1,
strokeColor: "#666666"
}
}
})
]
}),
"select": new OpenLayers.Style({
strokeColor: "#00ccff",
strokeWidth: 4
}),
"temporary": new OpenLayers.Style(null, {
rules: [
new OpenLayers.Rule({
symbolizer: {
"Point": {
pointRadius: 5,
graphicName: "square",
fillColor: "white",
fillOpacity: 0.25,
strokeWidth: 1,
strokeOpacity: 1,
strokeColor: "#333333"
},
"Line": {
strokeWidth: 3,
strokeOpacity: 1,
strokeColor: "#00ccff"
}
}
})
]
})
});


var saveStrategy = new OpenLayers.Strategy.Save();
wfs = new OpenLayers.Layer.Vector("Editable Features", {
strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
projection: new OpenLayers.Projection("EPSG:4326"),
styleMap: styles,
protocol: new OpenLayers.Protocol.WFS({
version: "1.1.0",
srsName: "EPSG:4326",
url: "http://localhost:8080/geoserver/wfs", // 自分の GeoServer
featureNS : "http://geoserver.sf.net", // drawinglineLine がある Workspace の名前空間
featureType: "drawinglineLine", // 修正
geometryName: "the_geom",
schema: "http://localhost:8080/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=sde:drawinglineLine" // 修正
})
});

map.addLayers([wms, wfs]);


  // configure the snapping agent
var snap = new OpenLayers.Control.Snapping({layer: wfs});
map.addControl(snap);
snap.activate();

// configure split agent
var split = new OpenLayers.Control.Split({
layer: wfs,
source: wfs,
tolerance: 0.0001,
deferDelete: true,
eventListeners: {
aftersplit: function(event) {
var msg = "Split resulted in " + event.features.length + " features.";
flashFeatures(event.features);
}
}
});
map.addControl(split);
split.activate();


// add some editing tools to a panel
var panel = new OpenLayers.Control.Panel(
{displayClass: 'customEditingToolbar'}
);
var draw = new OpenLayers.Control.DrawFeature(
wfs, OpenLayers.Handler.Path,
{
title: "Draw Feature",
displayClass: "olControlDrawFeaturePoint",
handlerOptions: {multi: true}
}
);
modify = new OpenLayers.Control.ModifyFeature(
wfs, {displayClass: "olControlModifyFeature"}
);
var del = new DeleteFeature(wfs, {title: "Delete Feature"});

var save = new OpenLayers.Control.Button({
title: "Save Changes",
trigger: function() {
if(modify.feature) {
modify.selectControl.unselectAll();
}
saveStrategy.save();
},
displayClass: "olControlSaveFeatures"
});

panel.addControls([
new OpenLayers.Control.Navigation(),
save, del, modify, draw
]);

panel.defaultControl = panel.controls[0];
map.addControl(panel);
map.addControl(new OpenLayers.Control.LayerSwitcher()); // 追加
map.addControl(new OpenLayers.Control.MousePosition()); // 追加
map.addControl(new OpenLayers.Control.ScaleLine()); // 追加
map.zoomTo(14);
}


function flashFeatures(features, index) {
if(!index) {
index = 0;
}
var current = features[index];
if(current && current.layer === wfs) {
wfs.drawFeature(features[index], "select");
}
var prev = features[index-1];
if(prev && prev.layer === wfs) {
wfs.drawFeature(prev, "default");
}
++index;
if(index <= features.length) {
window.setTimeout(function() {flashFeatures(features, index)}, 100);
}
}

</script>
</head>
<body onload="init()">

<h1 id="title">Snap/Split and Persist via WFS</h1>
<div id="tags"></div>
<p id="shortdesc">
Shows snapping, splitting, and use of the WFS Transactions (WFS-T).
</p>
<div id="map" class="smallmap"></div>
<div id="docs">
<p>The WFS protocol allows for creation of new features and reading,
updating, or deleting of existing features.</p>
<p>Use the tools to create, modify, and delete (in order from left
to right) features. Use the save tool (picture of a disk) to
save your changes. Use the navigation tool (hand) to stop editing
and use the mouse for map navigation.</p>
</div>
</body>
</html>



OpenLayers 56a Snap/Split and Persist via WFS - Snap と Split を WFS で保存 1

Snap/Split and Persist via WFS(wfs-snap-split.html)を参考に WFS レイヤに Snap and Split の結果の保存を試してみます。

シェイプファイルと GeoServer の設定

データベース tokyo に描画用テーブル drawingline を作成します。
PostGIS では保存できなかったので、Shapefile で編集可能レイヤを作成します。
river2_tokyo テーブルをコピーし1つのデータだけのテーブルを作成します。

user@debian:~$ psql tokyo
Welcome to psql 8.3.9, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

tokyo=> create table drawingline as select * from river_tokyo2 where gid = '1';
SELECT
tokyo=> \dt
List of relations
Schema | Name | Type | Owner
--------+------------------+-------+-------
public | drawing | table | user
public | drawingline | table | user
public | drawingpoint | table | user
public | geometry_columns | table | user
public | gyoseikai | table | user
public | pf_tokyo | table | user
public | population | table | user
public | railroad2 | table | user
public | railroad3 | table | user
public | river_tokyo2 | table | user
public | river_tokyo3 | table | user
public | spatial_ref_sys | table | user
(12 rows)

tokyo=> select gid, ric, cpu, wsc, eps, dus, slb, cop, rin, sos, eos, odc, dfd, sor, eor from drawingline ;
gid | ric | cpu | wsc | eps | dus | slb | cop | rin | sos | eos | odc | dfd | sor | eor
-----+------------+-----+--------+-----+-----+-----+-----+--------+-----+-----+-----+-----+-----+-----
1 | 8303050000 | | 830305 | | | | 0 | 小川谷 | | | 3 | 1 | |
(1 row)

tokyo=> \q

drawingline レイヤを GeoServer に追加します。
「Layer Configration」
1 ログインした GeoServer ページの左側の欄の「Data」の「Layers」をクリックします。
2 「Add a new resource」をクリックします。
3 「New Layer chooser」の「Add a layer from」ドロップダウンから「sde:Tokyo」を選択します。
4 Tokyo store のリソース(レイヤ)のリストが表示されます。
「drawingline」の「Publish」をクリックします。
5 選択したレイヤのリソースと編集した情報の設定をします。

「Basic Resource Info」を入力します。
Name: drawingline (変更なし)
Title: Drawing Line (最初の文字を大文字に変更 任意)
Abstract: Tokyo Drawing Line(任意)

「Keywords」を入力します。
Current Keywords: (追加したキーワードが表示されます)
New Keyword: drawing, line, tokyo (1つずつ入力して「追加」ボタンをクリック)

「Metadata links」は変更しません。

「Coordinate Reference Systems」を入力します。
Native SRS: 空(変更なし)
Declared SRS: EPSG:4326 (「Find」ボタンをクリックして「4326」を検索して表示された「4326」をクリック)
SRS handling: Force declared (変更しない)

6 「Bounding Boxes」を入力します。
Native Bounding Box: (「Compute from data」をクリック -以下の値が入力されました)
Min X: 139.018
Min Y: 35.89
Max X: 139.018
Max Y: 35.89
Lat/Lon Bounding Box: (「Compute from native bounds」をクリック -以下の値が入力されました)
Min X: 139.018
Min Y: 35.89
Max X: 139.018
Max Y: 35.89

7 ページ上部の「Publishing」タブをクリックします。
8 「Default Title」の「Default Style」を「line」にします。
(他は変更しません。)
9 ページ下部の「Save」ボタンをクリックします。

「Layers」ページの一番最後に「drawingline」が追加されます。
drawing レイヤの Shapefile を作成します。

1 GeoServer ページの左側の欄の「Layer Preview」をクリックします。
2 sde:drawingline の All Formats のドロップダウンリストで 「Shapefile」を選択します。
3 「drawingline.zip を開く」ダイアログで「ファイルを保存する」を選択し「OK」ボタンをクリックします。
4 「ファイル名を入れてください」ダイアログでデスクトップに保存しました。

この Shapefile を GeoServer に設定します。
1 drawingpoint.zip を解凍します。
2 geoserver-2.0.1/data_dir/data/drawing を作成します。
3 解凍したファイルを全部 geoserver-2.0.1/data_dir/data/drawing に入れます。

user@debian:~/Desktop$ ls
drawingline.zip featureserver-1.12 sld_data tilecache.csv
eclipse quicktime4linux-2.0.0 streaming tilecache2.csv
user@debian:~/Desktop$ unzip drawingline.zip
Archive: drawingline.zip
inflating: drawinglineLine.shx
inflating: drawinglineLine.shp
inflating: drawinglineLine.dbf
inflating: drawinglineLine.prj
inflating: drawinglineLine.cst
user@debian:~/Desktop$ ls
drawingline.zip drawinglineLine.shp quicktime4linux-2.0.0 tilecache2.csv
drawinglineLine.cst drawinglineLine.shx sld_data
drawinglineLine.dbf eclipse streaming
drawinglineLine.prj featureserver-1.12 tilecache.csv
user@debian:~/Desktop$ mv drawingline* ../geoserver-2.0.1/data_dir/data/drawing/

4 GeoServer ページの左側の欄の Data -> layers をクリックします。
5 Layers 画面の Add a new resource をクリックします。
6 New layer chooser 画面の Add layer from で sde:Tokyo_Shapefile を選択します。7 drawinglineLine の「Publish」をクリックします。

8 sde:drawinglineLine 画面で次のように設定します。

Data タブの
「Basic Rsource Info」を入力します。
Name: drawinglineLine(変更なし)
Title: Drawingline Line
Abstract: Tokyo MLIT River2 Shapefile

「Keywords」を入力します。
New Keyword: tokyo, river

「Metadata links」は入力しません。

「Coordinate Reference Systems」を入力します。
Native SRS: EPSG;4326(変更なし)
Declared SRS: EPSG;4326(変更なし)
SRS handling: Force declared(変更なし)

「Bounding Boxes」を入力します。
Native Bounding Box: (「Compute from data」をクリック -以下の値が入力されました)
Native Bounding Box: ()
Min X: 139.018
Min Y: 35.89
Max X: 139.018
Max Y: 35.89
Lat/Lon Bounding Box: (手動で入力してください。)
Min X: 139.018
Min Y: 35.89
Max X: 139.018
Max Y: 35.89

ページ上部の「Publishing」タブをクリックします。
「Default Title」の「Default Style」が「line」になっていることを確認します。
(他は変更しません。)
ページ下部の「Save」ボタンをクリックします。
「Layer」ページの一番下に「drawingpointLine」が追加されます。

2010年3月9日火曜日

OpenLayers 49 WFS United States (GeoServer) - GeoServer を使用した東京都マップ

WFS United States (GeoServer) Example(wfs-states.html)を参考に GeoServer を使用した東京都マップを作成してみます。

HTML ファイルを新規作成します。
「openlayersTokyoproj」 を右クリックして 新規 -> HTML ファイル をクリック。
「HTML ファイル」ウィンドウの「ファイル名(任意:openlayers_wfsstates.html)」に入力して「完了」ボタンをクリック。
「charset」を「utf-8」にします。
「examples」の「wfs-states.html」の内容をコピーして新規作成したファイルに貼り付けます。

コードの修正とちょっと解説します。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>OpenLayers49 WFS: Tokyo (GeoServer)</title>
<link rel="stylesheet" href="./theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="./examples/style.css" type="text/css" />

<!-- OpenLayers ライブラリ -->
<script src="./lib/Firebug/firebug.js"></script>
<script src="./lib/OpenLayers.js"></script>

<!-- Proj4js ライブラリ -->
<script type="text/javascript" src="./lib/proj4js/lib/proj4js-compressed.js"></script>
<script type="text/javascript" src="./lib/proj4js/lib/projCode/tmerc.js"></script>
<script type="text/javascript" src="./lib/proj4js/lib/defs/EPSG2456.js"></script>


<script type="text/javascript">
var map;

function init(){
OpenLayers.ProxyHost="/cgi-bin/proxy.cgi?url="; // 修正
// 東京都用 map の設定
map = new OpenLayers.Map('map', {
projection: new OpenLayers.Projection("EPSG:2456"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
maxResolution: 'auto',
units: 'meters',
maxExtent: new OpenLayers.Bounds(-279000,1054000,-185000,1104000)
},{
controls: [
new OpenLayers.Control.PanZoom(),
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.MouseDefaults()
]
});

// ここまで
// MapServer WMS リクエスト

var layer1 = new OpenLayers.Layer.WMS( "Tokyo Height WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/user/mapfile/tokyo_bmi_pgis_img2.map',
layers: 'height',
format: 'image/png'
});

var layer2 = new OpenLayers.Layer.WMS( "Tokyo Kukaku Sen WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/user/mapfile/tokyo_bmi_pgis_img2.map',
layers: 'kukaku',
transparent: true,
format: 'image/png'
});

// GeoServer WFS リクエスト

var layer3 = new OpenLayers.Layer.WFS( "Gyoseikai WFS",
"http://localhost:8080/geoserver/ows", // 自分の GeoServer
{
typename: 'sde:gyoseikai' // GeoServer に追加したレイヤ
},{
projection: new OpenLayers.Projection("EPSG:4326") // 追加
});

map.addLayers([layer1, layer2, layer3]); // 修正
// 次の3つのコントロールは、この位置でないと表示できませんでした。
map.addControl(new OpenLayers.Control.LayerSwitcher()); // 追加
map.addControl(new OpenLayers.Control.MousePosition()); // 追加
map.addControl(new OpenLayers.Control.ScaleLine()); // 追加
map.zoomToMaxExtent(); // 追加
}
</script>
</head>


<body onload="init()">
<h1 id="title">WFS United States (GeoServer) Example</h1>
<p id="shortdesc">
Shows the use of the WFS United States (GeoServer)
</p>
<div id="map" class="smallmap"></div>
</body>
</html>

root で proxy.cgi の allowHosts に 'localhost:8080' を追加します。
debian:/home/user# vim /usr/lib/cgi-bin/proxy.cgi

---
allowedHosts = ['www.openlayers.org', 'openlayers.org',
'labs.metacarta.com', 'world.freemap.in',
'prototype.openmnnd.org', 'geo.openplans.org',
'sigma.openplans.org', 'demo.opengeo.org',
'www.openstreetmap.org', 'sample.avencia.com',
'maps.google.co.jp', 'picasaweb.google.com',
'picasaweb.google.co.jp', 'api.flickr.com',
'jugl.tschaub.net',
'192.168.1.6', 'localhost', 'localhost:8080', '127.0.0.1' ]
---

表示に時間がかかります。
「応答のないスクリプト」ダイアログが表示されたときは、「処理を続行」をクリックしてください。

2010年3月8日月曜日

GeoServer を使った OpenLayers の examples 5 - WFS データの GeoServer と MapServer の比較

wget コマンドで確認した WFS の GetCapabilities のデータを比較してみます。

GeoServer
データは見やすいように整形しています。

user@debian:~$ wget -O geoserver_wfs_gc.xml "http://localhost:8080/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities"


<?xml version="1.0" encoding="UTF-8"?>
<wfs:WFS_Capabilities version="1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.opengis.net/wfs"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ows="http://www.opengis.net/ows"
xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd"
xmlns:cite="http://www.opengeospatial.net/cite"
xmlns:it.geosolutions="http://www.geo-solutions.it"
xmlns:tiger="http://www.census.gov"
xmlns:sde="http://geoserver.sf.net"
xmlns:topp="http://www.openplans.org/topp"
xmlns:sf="http://www.openplans.org/spearfish"
xmlns:nurc="http://www.nurc.nato.int"
updateSequence="57">
<ows:ServiceIdentification>
<ows:Title>GeoServer Web Feature Service</ows:Title>
<ows:Abstract>
This is the reference implementation of WFS 1.0.0 and WFS 1.1.0, supports all WFS operations including Transaction.
</ows:Abstract>
<ows:Keywords>
<ows:Keyword>WFS</ows:Keyword>
<ows:Keyword>WMS</ows:Keyword>
<ows:Keyword>GEOSERVER</ows:Keyword>
</ows:Keywords>
<ows:ServiceType>WFS</ows:ServiceType>
<ows:ServiceTypeVersion>1.1.0</ows:ServiceTypeVersion>
---
<FeatureTypeList>
<Operations>
<Operation>Query</Operation>
<Operation>Insert</Operation>
<Operation>Update</Operation>
<Operation>Delete</Operation>
<Operation>Lock</Operation>
</Operations>
<FeatureType xmlns:sde="http://geoserver.sf.net">
<Name>sde:gyoseikai</Name>
<Title>Gyoseikai</Title>
<Abstract>Land Numerical Info. Tokyo Gyoseikai</Abstract>
<ows:Keywords>
<ows:Keyword>gyoseikai</ows:Keyword>
<ows:Keyword>tokyo</ows:Keyword>
</ows:Keywords>
<DefaultSRS>urn:x-ogc:def:crs:EPSG:4326</DefaultSRS>
<ows:WGS84BoundingBox>
<ows:LowerCorner>136.069 20.425</ows:LowerCorner>
<ows:UpperCorner>153.987 35.898</ows:UpperCorner>
</ows:WGS84BoundingBox>
</FeatureType>
---

MapServer

user@debian:~$ wget -O mapserver_wfs_gc.xml "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_pf_pgis.map&service=WFS&request=GetCapabilities&version=1.0.0"


<?xml version='1.0' encoding="ISO-8859-1" ?>
<WFS_Capabilities
version="1.0.0"
updateSequence="0"
xmlns="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd">
---
<Service>
<Name>MapServer WFS</Name>
<!-- WARNING: Mandatory metadata '..._title' was missing in this context. -->
<Title>tokyo_pf_pgis_map</Title>
<OnlineResource>http://192.168.1.6/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_pf_pgis.map&</OnlineResource>
</Service>
---
<FeatureTypeList>
<Operations>
<Query/>
</Operations>
<FeatureType>
<Name>gyoseikai</Name>
<Title>Gyoseikai Tokyo mlit Map WMS Layer</Title>
<SRS>EPSG:4326</SRS>
<LatLongBoundingBox minx="-2.5e+07" miny="-2.5e+07" maxx="2.5e+07" maxy="2.5e+07" />
</FeatureType>
---

どちらもレイヤの Name、Title、SRS、BoundingBox のデータがあります。
gyoseikai レイヤの WFS データソースを取得します。
データを1つだけにしています。
Geoserver

http://localhost:8080/geoserver/wfs?service=wfs&version=1.1.0&request=GetFeature&typeName=sde:gyoseikai&maxFeatures=1


<wfs:FeatureCollection
numberOfFeatures="1"
timeStamp="2010-02-13T14:45:32.554+09:00"
xsi:schemaLocation="http://geoserver.sf.net
http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=sde%3Agyoseikai
http://www.opengis.net/wfs
http://localhost:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:tiger="http://www.census.gov"
xmlns:sde="http://geoserver.sf.net"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:topp="http://www.openplans.org/topp"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sf="http://www.openplans.org/spearfish"
xmlns:ows="http://www.opengis.net/ows"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xlink="http://www.w3.org/1999 xlink">
<gml:featureMembers>
<sde:gyoseikai gml:id="gyoseikai.1">
<sde:prn>東京都</sde:prn>
<sde:con>西多摩郡</sde:con>
<sde:cn2>奥多摩町</sde:cn2>
<sde:aac>13308</sde:aac>
<sde:the_geom>
<gml:MultiSurface srsName="urn:x-ogc:def:crs:EPSG:4326">
<gml:surfaceMember>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:posList>35.850868 139.163527 ...
</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
</gml:MultiSurface>
</sde:the_geom>
</sde:gyoseikai>
</gml:featureMembers>
</wfs:FeatureCollection>

MapServer

http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_pf_pgis.map&service=wfs&version=1.0.0&request=GetFeature&typeName=gyoseikai&maxFeatures=1


<?xml version='1.0' encoding="ISO-8859-1" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
http://mapserver.gis.umn.edu/mapserver http://192.168.1.6/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_pf_pgis.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=gyoseikai&OUTPUTFORMAT=XMLSCHEMA">
<gml:boundedBy>
<gml:Box srsName="EPSG4326">
<gml:coordinates>138.942865,35.501252 139.918904,35.898424</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<!-- WARNING: FeatureId item 'ID' not found in typename 'gyoseikai'. -->
<gml:featureMember>
<ms:gyoseikai>
<gml:boundedBy>
<gml:Box srsName="EPSG4326">
<gml:coordinates>138.942865,35.738576 139.178427,35.898424</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:Polygon srsName="EPSG4326">
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>139.163527,35.850868 ...
</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</ms:msGeometry>
<ms:gid>1</ms:gid>
<ms:prn>東京都</ms:prn>
<ms:sun></ms:sun>
<ms:con>西多摩郡</ms:con>
<ms:cn2>奥多摩町</ms:cn2>
<ms:aac>13308</ms:aac>
</ms:gyoseikai>
</gml:featureMember>
</wfs:FeatureCollection>

2つのデータには、名前空間に違いがあります。
行政区画名などの属性の名前空間は、GeoServer では Workspace 名に、MapServer では mapserver になっています。
また、GML の要素名にも違いがあります。