WebMapServiceでGIS
2009 年 5 月 22 日
コメントは受け付けていません。
GoogleMapのような地図のレンダリング機能が欲しくなりました。
しかもPythonで。
検索するとすぐ発見。
OwsLib。
インストールも簡単
sudo easy_install OWSLib
ちなみに、easy_installが使えない人は、先に以下のコマンドを実行。(Ubuntuでの話)
sudo apt-get install python-setuptools
さて、OWSLibの公式サイトに書いてあるスクリプトをチョロッと改造して、
東京近辺の地図を出してみました。
nasaが持っている地図から取得。
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
from owslib.wms import WebMapService
wms = WebMapService("http://wms.jpl.nasa.gov/wms.cgi", version="1.1.1")
img = wms.getmap( layers=['global_mosaic'],
styles=['visual_bright'],
srs='EPSG:4326',
bbox=(139.25, 35.25, 140.25, 36.25),
size=(640, 640),
format='image/jpeg',
transparent=True
)
out = open('tokyo_1.jpg', 'wb')
out.write(img.read())
out.close()
実行すると、tokyo_2.jpgファイルが作成されます。
こんな感じ。
簡単ですね。
WMSのサイトを変えて、日本の国土地理院の行政区画の区分地図を取得。
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
from owslib.wms import WebMapService
wms = WebMapService("http://www.finds.jp/ws/kiban25000wms.cgi", version="1.1.1")
img = wms.getmap( layers=['AdmArea'],
srs='EPSG:4326',
bbox=(139.25, 35.25, 140.25, 36.25),
size=(640, 640),
format='image/jpeg',
transparent=True
)
out = open('tokyo_2.jpg', 'wb')
out.write(img.read())
out.close()
これも簡単。


