Folium 활용

Python으로 지리공간 데이터 시각화하기

Mary van Valkenburg

Data Science Program Manager, Nashville Software School

미술 작품 위치 점이 표시된 연두색 폴리곤 플롯

Python으로 지리공간 데이터 시각화하기

Folium

  • 파이썬 패키지
  • 인터랙티브 지도
  • Leaflet.js 기반

folium 잎 로고

Python으로 지리공간 데이터 시각화하기

folium.Map()

import folium
# construct a map centered at the Eiffel Tower
eiffel_tower = folium.Map(location = [48.8583736,2.2922926])

# display the map
display(eiffel_tower)
Python으로 지리공간 데이터 시각화하기

파리 거리 지도

Python으로 지리공간 데이터 시각화하기

줌 레벨 설정

import folium
# construct a map centered at the Eiffel Tower
eiffel_tower = folium.Map([location = 48.8583736,2.2922926], zoom_start = 12)

# display the map
display(eiffel_tower)
Python으로 지리공간 데이터 시각화하기

에펠탑이 작게 보이는 파리 거리 지도

Python으로 지리공간 데이터 시각화하기

중심점으로 Folium 위치 지정

district_one.head()
district  center                   geometry
1         POINT (-86.860 36.262)   (POLYGON ((-86.771 36.383...    
center_point = district_one.center[0]
type(center_point)
<class 'shapely.geometry.point.Point'>
Python으로 지리공간 데이터 시각화하기

중심점으로 Folium 위치 지정

# reverse the order for folium location array
district_center = [center_point.y, center_point.x]

# print center point and district_center
print(center_point)
print(district_center)
POINT (-86.86086595994405 36.2628221811899)
[36.262822181189904, -86.86086595994405]
Python으로 지리공간 데이터 시각화하기

Folium 지도에 폴리곤 추가

# create a folium map centered on district 1
district1_map = folium.Map(location = district_center)
# add the outline of district one
folium.GeoJson(district_one.geometry).add_to(district1_map)
# display the resulting map
display(district1_map)
Python으로 지리공간 데이터 시각화하기

파란색 폴리곤이 표시된 지도

Python으로 지리공간 데이터 시각화하기

연습해 봅시다!

Python으로 지리공간 데이터 시각화하기

Preparing Video For Download...