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

2014年2月20日木曜日

36 - GeoEXT を使用した WFS-T 12 - 選択したレイヤの編集 2

36-12-2 選択したレイヤの属性の表示
3.1. Creating a Synchronized Grid and Map View of WFS Features(http://workshops.boundlessgeo.com/geoext/wfs/grid.html)の「Bonus Task」をコピーして貼り付け、一部を修正します。

---
// ここから追加
 var rawAttributeData;
 var read = OpenLayers.Format.WFSDescribeFeatureType.prototype.read;
 OpenLayers.Format.WFSDescribeFeatureType.prototype.read = function() {
  rawAttributeData = read.apply(this, arguments);
  return rawAttributeData;
 };
 function reconfigure(store, url) {
  var fields = [], columns = [], geometryName, geometryType;
  // regular expression to detect the geometry column
  var geomRegex = /gml:(Multi)?(Point|Line|Polygon|Surface|Geometry).*/;
  var types = {
   // mapping of xml schema data types to Ext JS data types
   "xsd:int": "int",
   "xsd:short": "int",
   "xsd:long": "int",
   "xsd:string": "string",
   "xsd:dateTime": "string",
   "xsd:double": "float",
   "xsd:decimal": "float",
   // mapping of geometry types
   "Line": "Path",
   "Surface": "Polygon"
  };
  store.each(function(rec) {
   var type = rec.get("type");
   var name = rec.get("name");
   var match = geomRegex.exec(type);
   if (match) {
    // we found the geometry column
    geometryName = name;
   } else {
    // we have an attribute column
    fields.push({
     name: name,
     type: types[type]
    });
    columns.push({
     xtype: types[type] == "string" ?
      "gridcolumn" :
      "numbercolumn",
     dataIndex: name,
     header: name
    });
   }
  });
  app.featureGrid.reconfigure(new GeoExt.data.FeatureStore({
   autoLoad: true,
   proxy: new GeoExt.data.ProtocolProxy({
    protocol: new OpenLayers.Protocol.WFS({
     url: url,
     version: "1.1.0",
     featureType: rawAttributeData.featureTypes[0].typeName,
     featureNS: rawAttributeData.targetNamespace,
//   srsName: "EPSG:4326",
     srsName: "EPSG:2451",
     geometryName: geometryName,
     maxFeatures: 250
    })
   }),
   fields: fields
  }), new Ext.grid.ColumnModel(columns));
  app.featureGrid.store.bind(vectorLayer);
  app.featureGrid.getSelectionModel().bind(vectorLayer);
 }
function setLayer(model, node) {
  if(!node || node.layer instanceof OpenLayers.Layer.Vector) {
   return;
  }
  vectorLayer.removeAllFeatures();
  app.featureGrid.reconfigure(
   new Ext.data.Store(),
   new Ext.grid.ColumnModel([])
  );
  var layer = node.layer;
  var url = layer.url.split("?")[0]; // the base url without params
  var schema = new GeoExt.data.AttributeStore({
   url: url,
   // request specific params
   baseParams: {
    "SERVICE": "WFS",
    "REQUEST": "DescribeFeatureType",
    "VERSION": "1.1.0",
    "TYPENAME": layer.params.LAYERS
   },
   autoLoad: true,
   listeners: {
    "load": function(store) {
     app.featureGrid.setTitle(layer.name);
     reconfigure(store, url);
    }
   }
  });
 }
 Ext.onReady(function() {
  app.tree.getSelectionModel().on(
   "selectionchange", setLayer
  );
 });
// ここまで
</script>
---

レイヤの属性の中で、「name」が表示されません。コード中に使用されている「name」に影響されているのかもしれません。属性の「name」を「term」に変更したら表示されるようになりました。

nippon_bmi=> ALTER TABLE akiruno_polygon RENAME name to term;
ALTER TABLE
nippon_bmi=> ALTER TABLE akiruno_line RENAME name to term;
ALTER TABLE
nippon_bmi=> ALTER TABLE akiruno_point RENAME name to term;
ALTER TABLE


GeoServer で akiruno_polygon akiruno_line akiruno_point レイヤの「Feature Type Details」を確認します。表示されないときは「Reload feature type」をクリックします。

36 - GeoEXT を使用した WFS-T 12 - 選択したレイヤの編集 1

36-12-1 akiruno_point と akiruno_line に 属性を追加
Developing OGC Compliant Web Applications with GeoExt の
3.1. Creating a Synchronized Grid and Map View of WFS Features(http://workshops.boundlessgeo.com/geoext/wfs/grid.html)と3.2. Editing Features and Their Attributes(http://workshops.boundlessgeo.com/geoext/wfs/editing.html)の「Bonus Task」を参考に、「Add to Map」で追加したレイヤを tree で選択して編集します。
「ol017-nippon_bmi_akiruno_pgis.html」をコピーして名前を付けて(「ol017bonus-nippon_bmi_akiruno_pgis.html」など)使います。

最初に、akiruno_point と akiruno_line に akiruno_polygon と同じように属性を追加します。

既存の属性
fid
the_geom
追加の属性
id  charactor varying(32)
name  charactor varying(32)
address  charactor varying(32)
createdate  charactor varying(32)
lastupdate  charactor varying(32)
category1  charactor varying(32)
category2  charactor varying(32)
category3  charactor varying(32)

user@debian7-vmw:~$ psql nippon_bmi
psql (9.1.11)
"help" でヘルプを表示します.
nippon_bmi=> ALTER TABLE akiruno_point ADD COLUMN id varchar(32);
---
ALTER TABLE
nippon_bmi=> ALTER TABLE akiruno_line ADD COLUMN id varchar(32);
---

nippon_bmi=> \d akiruno_point
                                 テーブル "public.akiruno_point"
   カラム   |          型           |                           修飾語                           
------------+-----------------------+-------------------------------------------------------------
 fid        | integer               | not null default nextval('akiruno_point_fid_seq'::regclass)
 the_geom   | geometry              | 
 id         | character varying(32) | 
 name       | character varying(32) | 
 address    | character varying(32) | 
 createdate | character varying(32) | 
 lastupdate | character varying(32) | 
 category1  | character varying(32) | 
 category2  | character varying(32) | 
 category3  | character varying(32) | 

インデックス:
    "akiruno_point_pkey" PRIMARY KEY, btree (fid)
    "spatial_akiruno_point_the_geom" gist (the_geom)
CHECK 制約:
    "enforce_dims_the_geom" CHECK (st_ndims(the_geom) = 2)
    "enforce_geotype_the_geom" CHECK (geometrytype(the_geom) = 'MULTIPOINT'::text OR the_geom IS NULL)
    "enforce_srid_the_geom" CHECK (st_srid(the_geom) = 2451)

(END):q


nippon_bmi=> \d akiruno_line
                                 テーブル "public.akiruno_line"
   カラム   |          型           |                           修飾語                           
------------+-----------------------+------------------------------------------------------------
 fid        | integer               | not null default nextval('akiruno_line_fid_seq'::regclass)
 the_geom   | geometry              | 
 id         | character varying(32) | 
 name       | character varying(32) | 
 address    | character varying(32) | 
 createdate | character varying(32) | 
 lastupdate | character varying(32) | 
 category1  | character varying(32) | 
 category2  | character varying(32) | 
 category3  | character varying(32) | 

インデックス:
    "akiruno_line_pkey" PRIMARY KEY, btree (fid)
    "spatial_akiruno_line_the_geom" gist (the_geom)
CHECK 制約:
    "enforce_dims_the_geom" CHECK (st_ndims(the_geom) = 2)
    "enforce_geotype_the_geom" CHECK (geometrytype(the_geom) = 'MULTILINESTRING'::text OR the_geom IS NULL)
    "enforce_srid_the_geom" CHECK (st_srid(the_geom) = 2451)

(END):q


GeoServer で akiruno_point と akiruno_line レイヤの「Feature Type Details」を確認します。表示されないときは「Reload feature type」をクリックします。

仮の属性の値を追加します。

nippon_bmi=> SELECT fid, id, name, createdate, lastupdate, category1, category2, category3 from akiruno_point;
 fid | id | name | createdate | lastupdate | category1 | category2 | category3 
-----+----+------+------------+------------+-----------+-----------+-----------
   2 |    |      |            |            |           |           | 
(1 行)

nippon_bmi=> UPDATE akiruno_point SET id = 'a', name = '点2', address = 'aki', createdate = '2014-2-14', lastupdate = '2014-2-14', category1 = 'c1', category2 = 'c2', category3 = 'c3' where fid = 2;
UPDATE 1
nippon_bmi=> SELECT fid, id, name, address, createdate, lastupdate, category1, category2, category3 from akiruno_line;
 fid | id | name | address | createdate | lastupdate | category1 | category2 | category3 
-----+----+------+---------+------------+------------+-----------+-----------+-----------
   3 |    |      |         |            |            |           |           | 

(1 行)
(stdin):q

nippon_bmi=> UPDATE akiruno_line SET id = 'a', name = '線2', address = 'aki', createdate = '2014-2-14', lastupdate = '2014-2-14', category1 = 'c1', category2 = 'c2', category3 = 'c3' where fid = 3;
UPDATE 1

2013年12月23日月曜日

32 - KML データの読込 2 - KML レイヤの表示

32-3 kml レイヤの例
examples フォルダにある「KML Layer Example(kml-layer.html)」を参考に KML ファイルを読み込んでレイヤを表示します。
最初に、HTML ファイルを準備します。
(Eclipse 4.2 Juno の調子が良くないので、4.3 Kepler standerd をインストールしました。少し手順が変わります。)

a 「App Exploler」ペインの「ol009-nippon_bmi_akiruno_pgis.html」を右クリックし「コピー」をクリックします。








b 「App Exploler」ペイン上で右クリックし「貼り付け」をクリックします。









c 「名前の競合」ウィンドウで「ol013-nippon_bmi_akiruno_pgis.html」と入力し「OK」ボタンをクリックします。



d 「App Exploler」ペインの「ol013-nippon_bmi_akiruno_pgis.html」をダブルクリックして開きます。
e メニューの「ファイル」->「開く」をクリックします。







f 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「examples」->「kml-layer.html」をクリックして選択し、「OK」ボタンをクリックします。
同じように「kml-layer.js」を開きます。





g 「kml-layer.js」の内容の一部をコピーして「ol013-nippon_bmi_akiruno_pgis.html」に貼り付け、次のように修正します。
(29-2 で追加したところは削除します。) 
---
 map.addLayers([layer0, layer3, layer1, layer2, layer4]);

 var kml_layer = new OpenLayers.Layer.Vector("KML", {
  strategies: [new OpenLayers.Strategy.Fixed()],
  projection: map.displayProjection, // 追加
  protocol: new OpenLayers.Protocol.HTTP({
   url: "kml/lines.kml", // ここを修正
   format: new OpenLayers.Format.KML({
    extractStyles: true, 
    extractAttributes: true,
    maxDepth: 2
   })
  })
 });
/*  ],
  center: new OpenLayers.LonLat(-112.169, 36.099),
  zoom: 11
 });
*/
 map.addLayer(kml_layer);

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

32-2 で作成したファイルを「openlayersTokyoproj」に保存します。
f ファイル -> 新規 -> フォルダー をクリックします。




g 「新規フォルダー」ウィンドウの「フォルダ名:」に「kml」と入力して「完了」ボタンをクリックします。









h 32-2 で作成したファイルを「kml」フォルダにコピーします。
(VMware Player で共有フォルダに設定したフォルダから g で作成したフォルダにコピーしました。)
user@debian7-vmw:~$ cp Public/Documents/*.kml mapsite/openlayersTokyoproj/kml/

i 「ここを修正」部分を次のように修正して地図を表示します。

url: "kml/Point.kml",










url: "kml/Line.kml",











url: "kml/Polygon.kml",


2013年12月17日火曜日

31 - GML データの読込 2 - Line と Polygon の表示

31-4 GML ファイルの作成 Line
examples フォルダの gml フォルダにある gml ファイルを参考にファイルを準備します。

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




b 「ファイル」ウィンドウで「openlayersTokyoproj」をクリックして選択し、「ファイル名」を「gml_line_akiruno.xml」と入力し、「完了」ボタンをクリックします。
314a-olaki.png







c 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「examples」->「gml」->「line.xml」をクリックして選択し、「OK」ボタンをクリックします。






d 「line.xml」の内容全部をコピーして「gml_line_akiruno.xml」に貼り付けて、次のように修正します。

<?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://aneto.oco/cgi-bin/worldwfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=line&OUTPUTFORMAT=XMLSCHEMA">


 <gml:boundedBy>
   <gml:Box srsName="EPSG:4326">
    <gml:coordinates>139.191,35.715 139.270,35.742</gml:coordinates>
   <!-- フィーチャ(3点)を含む範囲 -->
  </gml:Box>
 </gml:boundedBy>
  <gml:featureMember>
   <ms:line fid="1">
    <gml:boundedBy>
     <gml:Box srsName="EPSG:4326">
      <gml:coordinates>139.191,35.715 139.270,35.742</gml:coordinates>
      <!-- このフィーチャの範囲(線が1本なので上と同じ座標) -->
     </gml:Box>
    </gml:boundedBy>
    <ms:msGeometry>
     <gml:LineString srsName="EPSG:4326">
      <gml:coordinates>139.191,35.715 139.211,35.742 139.270,35.724</gml:coordinates>
     </gml:LineString>
    </ms:msGeometry>
    <ms:ogc_fid>1</ms:ogc_fid>
    <ms:name/>
    <ms:id>0</ms:id>
   </ms:line>
  </gml:featureMember>
 </wfs:FeatureCollection>


「ol012-nippon_bmi_akiruno_pgis.html」の「url: "gml_point_akiruno.xml",」を「url: "gml_line_akiruno.xml",」に修正します。

31-5 GML ファイルの作成 Polygon
examples フォルダの gml フォルダにある gml ファイルを参考にファイルを準備します。

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




b 「ファイル」ウィンドウで「openlayersTokyoproj」をクリックして選択し、「ファイル名」を「gml_polygon_akiruno.xml」と入力し、「完了」ボタンをクリックします。







c 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「examples」->「gml」->「polygon.xml」をクリックして選択し、「OK」ボタンをクリックします。

d 「polygon.xml」の内容全部をコピーして「gml_polygon_akiruno.xml」に貼り付けて、次のように修正します。

<?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://aneto.oco/cgi-bin/worldwfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=polygon&OUTPUTFORMAT=XMLSCHEMA">


 <gml:boundedBy>
  <gml:Box srsName="EPSG:4326">
   <gml:coordinates>139.191,35.715 139.270,35.742</gml:coordinates>
   <!-- フィーチャ(3点)を含む範囲 -->
  </gml:Box>
 </gml:boundedBy>
 <gml:featureMember>
  <ms:polygon fid="1">
   <gml:boundedBy>
    <gml:Box srsName="EPSG:4326">
     <gml:coordinates>139.191,35.715 139.270,35.742</gml:coordinates>
      <!-- このフィーチャの範囲(面が1個なので上と同じ座標) -->
    </gml:Box>
   </gml:boundedBy>
   <ms:msGeometry>
    <gml:MultiPolygon srsName="EPSG:4326">
     <gml:polygonMember>
      <gml:Polygon>
       <gml:outerBoundaryIs>
        <gml:LinearRing>
         <gml:coordinates>139.191,35.715 139.211,35.742 139.270,35.724</gml:coordinates>
        </gml:LinearRing>
       </gml:outerBoundaryIs>
      </gml:Polygon>
     </gml:polygonMember>
    </gml:MultiPolygon>
   </ms:msGeometry>
   <ms:ogc_fid>1</ms:ogc_fid>
   <ms:name>Polygon</ms:name>
   <ms:id>0</ms:id>
  </ms:polygon>
 </gml:featureMember>
</wfs:FeatureCollection>

「ol012-nippon_bmi_akiruno_pgis.html」の「url: "gml_line_akiruno.xml",」を「url: "gml_polygon_akiruno.xml",」に修正します。