simplekml と GroundOverlay を使って国連加盟国の国旗を表示するKMLを作成する

simplekml と GroundOverlay を使って画像を表示する KML ファイルを作成する の続きです。

前回の記事では 富士山の写真を表示した。

今回は 国連加盟国 の国旗を表示する。

国連加盟国の首都の位置に東西400km、南北200kmの大きさで国旗を表示する。

JSON ファイル(国連加盟国の一覧) を読み込んで for ループで処理する。

for item in list_countries:
    country = item['country']
    url_flag = item['url_flag']
    lat = item['lat']
    lon = item['lon']
    print(country)

    south = lat 
    west = lon
    north = lat + deg200 # 200km
    east = lon + deg400 # 400km

    ground = kml.newgroundoverlay(name=country)
    ground.icon.href = url_flag
    ground.latlonbox.north = north
    ground.latlonbox.south =  south
    ground.latlonbox.east =  east
    ground.latlonbox.west = west

この記事では 2種類のkMLファイルを作成する。

  • un_member_states_rectangle.kml
    首都の位置に長方形を表示する
  • un_member_states_overlay.kml
    首都の位置に国旗を表示する

作成した KMLファイルを Google Earth にインポートする

プログラムは GitHub に公開した。

https://github.com/ohwada/World_Countries/tree/main/simplekml/un_member_states_overlay