2008年9月13日土曜日

OpenLayers 9aFeature Info データの準備

OpenLayers9 Feature Info

地図属性(Map Feature)の情報を指定した場所に表示します。

シェイプファイルをデータベースに登録します。

template_postgisをテンプレートとして、オーナーがuserでkanagawaというデータベースを作成します。

postgres@debian:~$ createdb -T template_postgis -O user kanagawa_mlit
postgres@debian:~$ psql -l
List of databases
Name | Owner | Encoding
------------------+----------+----------
kamakura | user | UTF8
kanagawa | user | UTF8
kanagawa_mlit | user | UTF8
postgres | postgres | UTF8
template0 | postgres | UTF8
template1 | postgres | UTF8
template_postgis | postgres | UTF8
tokyo | user | UTF8
(8 rows)

kanagawa_mlitデータベースのgeometry_columnテーブルとspatial_ref_sysテーブルのオーナーをuserに変更します。

postgres@debian:~$ psql kanagawa_mlit
Welcome to psql 8.3.3, 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

kanagawa_mlit=# \d
List of relations
Schema | Name | Type | Owner
--------+------------------+-------+----------
public | geometry_columns | table | postgres
public | spatial_ref_sys | table | postgres
(2 rows)

kanagawa_mlit=# ALTER TABLE geometry_columns OWNER TO user;
ALTER TABLE
kanagawa_mlit=# ALTER TABLE spatial_ref_sys OWNER TO user;
ALTER TABLE
kanagawa_mlit=# \d
List of relations
Schema | Name | Type | Owner
--------+------------------+-------+-------
public | geometry_columns | table | user
public | spatial_ref_sys | table | user
(2 rows)

kanagawa_mlit=# \q

shp2pgsqlコマンドを使ってシェイプファイルをデータベースに登録します。
一般ユーザでシェイプファイルのあるディレクトリに移動して、次のように入力します。

postgres@debian:~$ exit
logout
user@debian:~$ cd mapdata/kanagawa_mlit/
user@debian:~/mapdata/kanagawa_mlit$ ls
N03-071001_14_EC01.dbf P02-06_14_FB01.dbf facilities_kanagawa.zip
N03-071001_14_EC01.shp P02-06_14_FB01.shp
N03-071001_14_EC01.shx P02-06_14_FB01.shx
user@debian:~/mapdata/kanagawa_mlit$ shp2pgsql -W sjis N03-071001_14_EC01.shp gyoseikai > gyoseikai.sql
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
user@debian:~/mapdata/kanagawa_mlit$ shp2pgsql -W sjis P02-06_14_FB01.shp publicfacilities > publicfacilities.sql
Shapefile type: Point
Postgis type: POINT[2]

shp2pgsqlコマンドを使ってシェイプファイルをデータベースに登録します。
一般ユーザでシェイプファイルのあるディレクトリに移動して、次のように入力します。

user@debian:~/mapdata/kanagawa_mlit$ ls
N03-071001_14_EC01.dbf P02-06_14_FB01.dbf facilities_kanagawa.zip
N03-071001_14_EC01.shp P02-06_14_FB01.shp gyoseikai.sql
N03-071001_14_EC01.shx P02-06_14_FB01.shx publicfacilities.sql
user@debian:~/mapdata/kanagawa_mlit$ psql -d kanagawa_mlit -f gyoseikai.sql > log.txt
psql:gyoseikai.sql:8: NOTICE: CREATE TABLE will create implicit sequence "gyoseikai_gid_seq" for serial column "gyoseikai.gid"
psql:gyoseikai.sql:8: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "gyoseikai_pkey" for table "gyoseikai"
user@debian:~/mapdata/kanagawa_mlit$ vim log.txt
SET
BEGIN
CREATE TABLE
addgeometrycolumn
------------------------------------------------------------
public.gyoseikai.the_geom SRID:-1 TYPE:MULTIPOLYGON DIMS:2


(1 row)

INSERT 0 1
---
COMMIT

user@debian:~/mapdata/kanagawa_mlit$ psql kanagawa_mlitWelcome to psql 8.3.3, 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

kanagawa_mlit=> \dt
List of relations
Schema | Name | Type | Owner
--------+------------------+-------+-------
public | geometry_columns | table | user
public | gyoseikai | table | user
public | spatial_ref_sys | table | user
(3 rows)

kanagawa_mlit=> \d gyoseikai
Table "public.gyoseikai"
Column | Type | Modifiers
----------+-----------------------+---------------------------------------------------------
gid | integer | not null default nextval('gyoseikai_gid_seq'::regclass)
prn | character varying(8) |
sun | character varying(1) |
con | character varying(8) |
cn2 | character varying(10) |
aac | character varying(5) |
the_geom | geometry |
Indexes:
"gyoseikai_pkey" PRIMARY KEY, btree (gid)
Check constraints:
"enforce_dims_the_geom" CHECK (ndims(the_geom) = 2)
"enforce_geotype_the_geom" CHECK (geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL)
"enforce_srid_the_geom" CHECK (srid(the_geom) = (-1))

kanagawa_mlit=> \q


残りのシェイプファイルも登録します。

user@debian:~/mapdata/kanagawa_mlit$ psql -d kanagawa_mlit -f publicfacilities.sql > log2.txt
psql:publicfacilities.sql:17: NOTICE: CREATE TABLE will create implicit sequence "publicfacilities_gid_seq" for serial column "publicfacilities.gid"
psql:publicfacilities.sql:17: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "publicfacilities_pkey" for table "publicfacilities"

user@debian:~$ cd mapdata/railroad_mlit/
user@debian:~/mapdata/railroad_mlit$ ls
N02-07_EB02.dbf N02-07_EB02.shx N02-07_EB03.shp
N02-07_EB02.shp N02-07_EB03.dbf N02-07_EB03.shx
user@debian:~/mapdata/railroad_mlit$ shp2pgsql -W sjis N02-07_EB02.shp railroad1 > railroad1.sql
Shapefile type: Arc
Postgis type: MULTILINESTRING[2]
user@debian:~/mapdata/railroad_mlit$ shp2pgsql -W sjis N02-07_EB03.shp railroad2 > railroad2.sql
Shapefile type: Arc
Postgis type: MULTILINESTRING[2]
user@debian:~/mapdata/railroad_mlit$ ls
N02-07_EB02.dbf N02-07_EB02.shx N02-07_EB03.shp railroad1.sql
N02-07_EB02.shp N02-07_EB03.dbf N02-07_EB03.shx railroad2.sql
user@debian:~/mapdata/railroad_mlit$ psql -d kanagawa_mlit -f railroad1.sql > log1.txt
psql:railroad1.sql:7: NOTICE: CREATE TABLE will create implicit sequence "railroad1_gid_seq" for serial column "railroad1.gid"
psql:railroad1.sql:7: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "railroad1_pkey" for table "railroad1"
user@debian:~/mapdata/railroad_mlit$ psql -d kanagawa_mlit -f railroad2.sql > log2.txt
psql:railroad2.sql:8: NOTICE: CREATE TABLE will create implicit sequence "railroad2_gid_seq" for serial column "railroad2.gid"
psql:railroad2.sql:8: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "railroad2_pkey" for table "railroad2"

0 件のコメント: