LoginSignup
2
2

More than 3 years have passed since last update.

simplekmlのシンプルな使い方

Last updated at Posted at 2019-05-29

初カキコ…ども…

表題の通りですが、簡単に使い方を説明していこうと思います

simplekmlとは

簡単に言えばKMLをシンプルに作成できるpythonのパッケージですね。
あんまりsimplekmlに関する記事がないようでしたので、自分のコードとかを備忘録的に記事にしておこうと思いました。

記事作成時点でのバージョンは1.3.1になります。
https://simplekml.readthedocs.io/en/latest/index.html

めちゃ簡単なsample

simplekml.py
kml = simplekml.Kml()
kml.newpoint(name="Kirstenbosch", coords=[(18.432314,-33.988862)])  # lon, lat, optional height
kml.save("botanicalgarden.kml")

ざっくりこれだけでkmlが作れます。
sampleでは点だけを作ってますが、これ以外にもpolygonやlineが描画できます。
またフォルダを作成して、その中にpointやlineを作ることももちろん可能です。

ポリゴンのスタイル

polygonやline,pointにはそれぞれスタイルが設定できます。
設定できるものはオブジェクトによって違います。詳細は公式Documentを参照してください

polygonStyle.py
pol = kml.newpolygon(name = testName)
pol.outerboundaryis = [a, b, c, d, a]
pol.style.linestyle.color = "bf00ffff"
pol.style.polystyle.color = "3f00ff00"
pol.style.linestyle.width = 3

上のサンプルではまずポリゴンの外形境界線(outerBoundary)を設定し
境界線の色、ポリゴンの色、境界線の太さを設定しています。
また、このほかに内側の境界線(innerBoundary)を設定することもできます。

ポイントのスタイル

pointStyle.py
point = kml.newpoint(name = testName)
point.coords = [(a,b)]
point.style.iconstyle.icon.href = None
point.style.labelstyle.scale = 0.8

pointのスタイルになります。
割と使いそうなのはiconstyleだと思います。
こう記述するとiconなしで表示することができます。

注意点

最後に注意したい点なんですが、kmlの座標の表記は度分秒ではなく十進数表記になります。
若干めんどうなんですけど、そこだけ注意してください。

おわり

いかがでしたか!?
初めての記事なのでちょっと締めの言葉がわかりません。

以上です。

2019/07/18
一部修正しました。内容に変更はありません。

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2