https://python-visualization.github.io/folium/
GeoDataFrame を Folium で地理院地図ベースに図化する例です。
※見やすさのため不要なインデントをつけています。
- import folium
- ##ポリゴンからコロプレスマップ
- #地物の数が多い(数万)とブラウザがクラッシュ。
- m = folium.Map([36, 140],
- zoom_start=7,
- tiles='https://cyberjapandata.gsi.go.jp/xyz/pale/{z}/{x}/{y}.png',
- attr='淡色地図')
- m.choropleth(
- geo_data=gdf,
- name='choropleth',
- data=df,#gdfとdfは結合していない
- columns=['key', 'A'], # dfのkeyと表示データ
- key_on='feature.properties.A', # gdfのキー
- fill_color='YlGn',# 色パレットを指定
- threshold_scale=[0,2,4,6,8,10,12,14], # 段階
- fill_opacity=0.7,
- line_opacity=0.2,
- legend_name='aaa')
- m # ポリゴンの多い場合は、コメントアウトして表示させない。
- m.save('./AAA.html')
- ##ポイント
- #ポイント表示は数千まで?
- #多い場合は表示させずにhtml保存。
- #GeoDataFrameを種類で分割
- gdfA=gdf[(gdf['A']==aaa)]
- gdfB=gdf[(gdf['A']==bbb)]
- #ベースマップ
- m = folium.Map([36, 140],
- zoom_start=9,
- tiles='https://cyberjapandata.gsi.go.jp/xyz/pale/{z}/{x}/{y}.png',
- attr='淡色地図')
- #1種類目:赤色でプロット
- for index, row in gdfA.iterrows():
- p_txt = '種類:' + row['A']
- p_txt = p_txt + '年月日:' +
- str(row['年'])+'/'+
- str(row['月'])+'/'+
- str(row['日'])
- popup = folium.Popup(p_txt, max_width=2650)
- folium.Circle(#units of meters
- #folium.CircleMarker(#units of pixcels
- radius=100,
- location=[gdfA.Lat[index], gdfA.Lng[index]],
- popup=popup,
- color='red',
- fill_opacity=0.5, line_opacity=1,
- fill=True,
- fill_color='red'
- ).add_to(m)
- #2種類目:青色でプロット
- for index, row in gdfB.iterrows():
- p_txt = '種類:' + row['A']
- p_txt = p_txt + '年月日:' +
- str(row['年'])+'/'+
- str(row['月'])+'/'+
- str(row['日'])
- popup = folium.Popup(p_txt, max_width=2650)
- folium.Circle(#units of meters
- #folium.CircleMarker(#units of pixcels
- radius=100,
- location=[gdfB.Lat[index], gdfB.Lng[index]],
- popup=popup,
- color='blue',
- fill_opacity=0.5, line_opacity=1,
- fill=True,
- fill_color='blue'
- ).add_to(m)
- m # ポイントの多い場合はコメントアウトして表示させない。
- m.save('./AAA.html')
0 件のコメント:
コメントを投稿