Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
software_development:python_folium_map [2020/04/27 02:17] – created prgram | software_development:python_folium_map [2025/07/07 14:12] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 5: | Line 5: | ||
- | 행정동 경계 그리기 | + | === map 생성, 초기화 === |
+ | <code python> | ||
+ | import folium | ||
+ | m = folium.Map(location=[37.6, | ||
+ | </ | ||
- | Marker, Circle | + | ===행정동 경계 그리기=== |
+ | https:// | ||
+ | [[data_analysis: | ||
+ | geojson 이용 | ||
+ | <code python> | ||
+ | nodeData = ' | ||
+ | nodeData = open(nodeData, encoding = " | ||
- | FastMarkerCluster | + | import json |
+ | nodes = json.loads(nodeData) | ||
+ | geo_json = folium.GeoJson(nodeData, | ||
+ | geo_json = folium.GeoJson(nodes, | ||
+ | geo_json.add_to(m) | ||
+ | </ | ||
+ | line 7-8: string이나 json으로 변환된 변수나 모두 적용가능 | ||
+ | smooth_factor 값이 크면, performance 상승(smoothness와 trade-off) (([https:// | ||
+ | GeoJsonTooltip 에 Series 를 넣으면 자동으로 tooltip 생성 | ||
+ | GeoJsonPopUp 은 버전 때문에 안되는듯? | ||
+ | |||
+ | |||
+ | ===Marker, Circle=== | ||
+ | |||
+ | ==Circle (bubble)== | ||
+ | <code python> | ||
+ | from tqdm import tqdm | ||
+ | for x in tqdm(dcd): | ||
+ | for i,l in enumerate(li): | ||
+ | tmp = df[df.dv_nm==l][df.admin_dcd==x] | ||
+ | lat = tmp[' | ||
+ | lon = tmp[' | ||
+ | count = len(tmp) | ||
+ | if pd.isnull(lat) or pd.isnull(lon): | ||
+ | continue | ||
+ | folium.CircleMarker((lat, | ||
+ | |||
+ | folium.LayerControl(collapsed=False).add_to(m) | ||
+ | </ | ||
+ | li,col : dv_nm 에 따라 색을 다르게 함 | ||
+ | |||
+ | ==Marker== | ||
+ | <code python> | ||
+ | from tqdm import tqdm | ||
+ | for x in tqdm(range(len(df))): | ||
+ | |||
+ | if df.iloc[x,: | ||
+ | color = ' | ||
+ | elif df.iloc[x,: | ||
+ | color = ' | ||
+ | |||
+ | location = (latitude[x], | ||
+ | folium.Marker(location, | ||
+ | </ | ||
+ | | ||
+ | ===Marker Cluster === | ||
+ | Zoom에 따라서 Cluster 를 만들어줌 | ||
+ | <code python> | ||
+ | from folium.plugins import MarkerCluster | ||
+ | mc = MarkerCluster() | ||
+ | |||
+ | for i,row in tqdm(df_store.iterrows()): | ||
+ | lat = row[' | ||
+ | lon = row[' | ||
+ | if math.isnan(lat) or math.isnan(lon): | ||
+ | continue | ||
+ | # | ||
+ | |||
+ | mc.add_child(folium.Marker(location=[lat, | ||
+ | |||
+ | m.add_child(mc) | ||
+ | # Save to html | ||
+ | m.save(os.path.join('', | ||
+ | </ | ||
+ | |||
+ | ===FastMarkerCluster=== | ||
+ | https:// | ||
+ | https:// | ||
+ | https:// | ||
+ | |||
+ | zoom 에 따라서 Cluster 를 만들어줌. | ||
+ | Fast는 javascript에서 직접 실행해서 더 빠름 | ||
+ | |||
+ | <code python> | ||
+ | from folium.plugins import FastMarkerCluster | ||
+ | </ | ||
+ | |||
+ | ==Circle== | ||
+ | <code python> | ||
+ | callback = (""" | ||
+ | var circle = L.circle(new L.LatLng(row[0], | ||
+ | |||
+ | var popup = L.popup({maxWidth: | ||
+ | const display_text = {text: row[2]}; | ||
+ | var mytext = $(`<div id=' | ||
+ | popup.setContent(mytext); | ||
+ | circle.bindPopup(popup); | ||
+ | |||
+ | return circle; | ||
+ | | ||
+ | m.add_child(FastMarkerCluster(df[df.dv_nm==li[1]][[' | ||
+ | </ | ||
+ | |||
+ | ==Marker == | ||
+ | <code python> | ||
+ | callback = (' | ||
+ | 'var marker = L.marker(new L.LatLng(row[0], | ||
+ | 'var icon = L.AwesomeMarkers.icon({' | ||
+ | "icon: ' | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ' | ||
+ | ' | ||
+ | "var popup = L.popup({maxWidth: | ||
+ | " | ||
+ | "var mytext = $(`<div id=' | ||
+ | " | ||
+ | " | ||
+ | ' | ||
+ | m.add_child(FastMarkerCluster(df[[' | ||
+ | </ | ||
+ | row[0,1,2] 를 사용 | ||
+ | popup | ||
+ | |||
+ | ===map 저장=== | ||
+ | |||
+ | <code python> | ||
+ | m.save(os.path.join('', | ||
+ | </ | ||
{{tag> | {{tag> |