2008年8月7日木曜日

PostGISで地図を表示 8東京都のマップファイルと地図

東京都の人口を階級区分して色分けして表示します。

tokyo_shp2.mapをコピーしてtokyo_pgis_color.mapを作成します。
マップファイルのレイヤ部分を記述します。

MAP
NAME tokyo_pgis_color_map
---
LAYER
NAME gyoseikai
GROUP gyoseikai
TYPE POLYGON
STATUS ON
CONNECTIONTYPE POSTGIS
CONNECTION "dbname=tokyo host=localhost user=user password=password"
DATA "the_geom FROM (
SELECT gyoseikai.gid AS gid, #PostGISは大文字小文字を区別します
gyoseikai.gun_seirei AS gun_seirei,
gyoseikai.shikuchoso AS shikuchoso,
gyoseikai.code AS code,
gyoseikai.the_geom AS the_geom,
population.total AS total,
population.male AS male,
population.female AS female,
population.foreigner AS foreigner
FROM gyoseikai LEFT OUTER JOIN population ON gyoseikai.code = population.code)
AS gyosei_pop USING UNIQUE gid USING SRID=-1"
LABELITEM "shikuchoso"
METADATA
"group_title" "行政界"
"queryable" "true"
"searchfield" "shikuchoso"
"fields" "gun_seirei:郡政令,shikuchoso:市区町村,total:人口" #ここを修正
END
CLASS
NAME "行政界"
STYLE
OUTLINECOLOR 153 153 153
END
LABEL
MINFEATURESIZE 40
TYPE TRUETYPE
FONT vl-gothic
ENCODING UTF-8
SIZE 8
END
END
TEMPLATE temp_tokyo_pgis.html #ここを修正
END

LAYER #ダミーのレイヤ
NAME gyoseikai2
GROUP totalpop
TYPE POLYGON
STATUS ON
CONNECTIONTYPE POSTGIS
CONNECTION "dbname=tokyo host=localhost user=user password=password"
DATA "the_geom FROM (
SELECT gyoseikai.gid AS gid,
gyoseikai.gun_seirei AS gun_seirei,
gyoseikai.shikuchoso AS shikuchoso,
gyoseikai.code AS code,
gyoseikai.the_geom AS the_geom,
population.total AS total,
population.male AS male,
population.female AS female,
population.foreigner AS foreigner
FROM gyoseikai LEFT OUTER JOIN population ON gyoseikai.code = population.code)
AS gyosei_pop USING UNIQUE gid USING SRID=-1"
LABELITEM "shikuchoso"
METADATA
"group_title" "人口"
END
CLASS
NAME "行政界"
STYLE
OUTLINECOLOR 153 153 153
END
LABEL
MINFEATURESIZE 40
TYPE TRUETYPE
FONT vl-gothic
ENCODING UTF-8
SIZE 8
END
END
END

LAYER #このレイヤを追加
NAME totalpop
GROUP totalpop
TYPE POLYGON
STATUS ON
CONNECTIONTYPE POSTGIS
CONNECTION "dbname=tokyo host=localhost user=user password=password"
DATA "the_geom FROM (
SELECT gyoseikai.gid AS gid,
gyoseikai.gun_seirei AS gun_seirei,
gyoseikai.shikuchoso AS shikuchoso,
gyoseikai.code AS code,
gyoseikai.the_geom AS the_geom,
population.total AS total,
population.male AS male,
population.female AS female,
population.foreigner AS foreigner
FROM gyoseikai LEFT OUTER JOIN population ON gyoseikai.code = population.code)
AS gyosei_pop USING UNIQUE gid USING SRID=-1"
OPACITY 50
CLASSITEM "total"
METADATA
"group_title" "人口"
END
CLASS
NAME "50万人以上"
EXPRESSION ([total] >= 500000)
COLOR 255 0 0
END
CLASS
NAME "40万-50万人"
EXPRESSION ([total] < 500000 AND [total] >= 400000)
COLOR 255 51 51
END
CLASS
NAME "30万-40万人"
EXPRESSION ([total] < 400000 AND [total] >= 300000)
COLOR 255 102 102
END
CLASS
NAME "20万-30万人"
EXPRESSION ([total] < 300000 AND [total] >= 200000)
COLOR 255 153 153
END
CLASS
NAME "10万人-20万人"
EXPRESSION ([total] < 200000 AND [total] >= 100000)
COLOR 255 204 204
END
END

LAYER
NAME gun_seirei
GROUP gun_seirei
TYPE ANNOTATION
STATUS ON
CONNECTIONTYPE POSTGIS
CONNECTION "dbname=tokyo host=localhost user=user password=password"
DATA "the_geom FROM (
SELECT gyoseikai.gid AS gid,
gyoseikai.gun_seirei AS gun_seirei,
gyoseikai.shikuchoso AS shikuchoso,
gyoseikai.code AS code,
gyoseikai.the_geom AS the_geom,
population.total AS total,
population.male AS male,
population.female AS female,
population.foreigner AS foreigner
FROM gyoseikai LEFT OUTER JOIN population ON gyoseikai.code = population.code)
AS gyosei_pop USING UNIQUE gid USING SRID=-1"
LABELITEM "gun_seirei"
METADATA
"group_title" "郡政令"
"searchfield" "gun_seirei"
"fields" "gun_seirei:郡政令,shikuchoso:市区町村,total:人口"
END
CLASS
NAME "郡政令"
LABEL
MINFEATURESIZE 40
TYPE TRUETYPE
FONT vl-gothic
ENCODING UTF-8
SIZE 8
POSITION uc
END
END
TEMPLATE temp_tokyo_pgis.html #ここを修正
END

END #MAP END

temp_tokyo_pgis.htmlを作成します。
temp_tokyo_shp.htmlをコピーしてファイル名を変えます。
内容を次のように修正します。

<html>
<head>
<title>Tokyo pgis Template</title> #ここを修正
</head>
<body>
<li>[gun_seirei]
<li>[shikuchoso]
<li>[total] #ここを追加
</body>
</html>

config.phpの内容をつぎのように修正します。

$aszTokyo = array (
'title' => 'Tokyo',
'path' => '/home/nob61/mapfile/tokyo_pgis_color.map',
'scales' => array( 500000, 250000, 100000 ),
'format' =>'PNG'
);


0 件のコメント: