PostGIS のポリゴンを MapServer で表示してみる
MapServerサイドでは mapファイルと、テンプレートHTMLファイルが必要です。
mapファイルの作成は http://www.ne.jp/asahi/free/hiroro/postgis/manual/x549.html を参考にしました。ただし、shp2pgsql が吐くスクリプトでは、ジオメトリデータの入っているフィールドは "the_geom" です。
まず mapファイルを作成。
MAP NAME JAPAN STATUS ON SIZE 300 300 EXTENT 122 23 151 46 WEB TEMPLATE "template.html" END LAYER CONNECTIONTYPE postgis NAME "japan" CONNECTION "user=<ユーザ名> dbname=japan host=localhost" DATA "the_geom from city" STATUS ON TYPE LINE CLASS COLOR 128 128 128 END END END
次に、itasca demo から流用して、htmlファイルを2つ作成。
index.html はこんなかんじ。
<html> <head> <title>Japan Map</title> </head> <body> <form method="GET" action="/cgi-bin/mapserv"> <input type="hidden" name="layer" value="japan"> <input type="hidden" name="zoomsize" value=2> <input type="hidden" name="map" value="<mapファイルへのローカルパス>"> <input type="hidden" name="map_web_imagepath" value="<画像保存場所へのローカルパス>"> <input type="hidden" name="map_web_imageurl" value="<画像保存場所へのURL>"> <input type="submit" value="DO IT!"> </form> </body> </html>
template.html はこんなかんじ。
<html> <head> <title>Japan Map</title> </head> <body> <form method="GET" action="/cgi-bin/mapserv"> <input type="hidden" name="layer" value="japan"> <input type="image" name="img" src="[img]" width="[mapwidth]" height="[mapheight]" alt="map image"> <input type="hidden" name="imgxy" value="[center]"> <input type="hidden" name="imgext" value="[mapext]"> <input type="hidden" name="map" value="[map]"> <input type="hidden" name="savequery" value="true"> <input type="hidden" name="map_web_imagepath" value="[map_web_imagepath]"> <input type="hidden" name="map_web_imageurl" value="[map_web_imageurl]"> <br> <input type="submit" value="Refresh/Query"> <br> +<input type=radio name=zoomdir value=1 [zoomdir_1_check]> *<input type=radio name=zoomdir value=0 [zoomdir_0_check]> -<input type=radio name=zoomdir value=-1 [zoomdir_-1_check]> <br> Zoom Size <input type="text" name="zoomsize" size="4" value=[zoomsize]> </form> </body> </html>