simplekml と GroundOverlay を使って画像を表示する KML ファイルを作成する
の続きです。
前回の記事では 富士山の写真を表示した。
今回は 南極観測基地 に国旗を表示する。
やり方は simplekml と GroundOverlay を使って国連加盟国の国旗を表示するKMLを作成する とほぼ同じ
この記事では 南極観測基地の位置に東西400km、南北200kmの大きさで国旗を表示する。
JSON ファイル(南極観測基地の一覧) を読み込んで for ループで処理する。
for item in list_stations: station = item['station'] url_station = item['url_station'] url_country_flag = item['url_country_flag'] lat = item['lat'] lon = item['lon'] print(station) rad = math.radians( abs(lat) ) lon_deg = 360.0/ (40000.0 * math.cos(rad) ) # (deg/km) height = int( (WIDTH * country_flag_height) / country_flag_width ) south = lat west = lon north = lat + (height * lat_deg ) east = lon + ( WIDTH * lon_deg ) ground = kml.newgroundoverlay(name=station) ground.icon.href = url_country_flag ground.latlonbox.north = north ground.latlonbox.south = south ground.latlonbox.east = east ground.latlonbox.west = west
南極点(緯度-90度)の アムンゼン・スコット基地 は別扱い。
「緯度-90度」では北辺が点になるので 「緯度-88度」に修正する。
lat_amundsen = -88.0 lon_amundsen = 10.0 if lat < -89.0: height = int( (WIDTH * country_flag_height) / country_flag_width ) south = lat_amundsen west = lon_amundsen north = south + ( height * lat_deg ) east = west + ( WIDTH * lon_deg_amundsen )
南極点に円形を表示する
lat_pole = -89.0 lon_pole = 0.0 radius = 50000 # 50 km polycircle = polycircles.Polycircle(latitude=lat_pole, longitude=lon_pole, radius=radius, number_of_vertices=36) polygon1 = kml1.newpolygon(name=name, outerboundaryis=polycircle.to_kml())
作成した KMLファイルを Google Earth にインポートする。
アムンゼン・スコット基地の国旗は 長方形でなく 扇型になるが、 これは仕方ないか。
プログラムは GitHub に公開した。
https://github.com/ohwada/World_Countries/tree/main/simplekml/antarctic_research_stations_overlay