급속 충전소 최적 입지 선정 프로젝트 중 현재의 충전소간 거리를 확인해보고자 한다.
현재의 충전소간 거리가 멀면 충전소 입지가 더 필요할 것이고 거리가 짧으면 그렇지 않을 것이다.
이는 geopandas를 사용하는데, 우선 우리나라 최신 행정구역 shp파일을 받아둔다.
읍면동 데이터의 최신 버전을 다운로드 받았다.
http://www.gisdeveloper.co.kr/?p=2332

# 라이브러리 호출
import geopandas as gpd
# 서울시 법정동 경계 데이터 불러오기
dong_boundary = gpd.read_file('/Users/sookyeong/Documents/내배캠/팀프로젝트/project5_final/emd.shp', encoding='cp949')

파일을 불러오면 평소 사용하는 WGS84 좌표가 아니다.
우선 CSR로 EPSG:5179으로 변환해주어야 한다.
# CRS 설정
dong_boundary.crs = 'EPSG:5179'
'EPSG:5179'는 GeoDataFrame의 좌표 참조 시스템(CRS)을 'EPSG:5179'로 설정하는 것을 의미한다.EPSG(European Petroleum Survey Group)는 좌표 참조 시스템에 대한 표준 데이터 세트를 관리하는 국제적인 조직입니다. 'EPSG:5179'는 대한민국 내에서 주로 사용되는 좌표 참조 시스템 중 하나라고 한다.
# 중심점 좌표 계산
dong_boundary['center_point'] = dong_boundary['geometry'].centroid
# 좌표를 WGS 84 좌표계로 변환
dong_boundary['geometry'] = dong_boundary['geometry'].to_crs(epsg=4326)
dong_boundary['center_point'] = dong_boundary['center_point'].to_crs(epsg=4326)
그 다음은 간단하다.
중심점을 찾고 그 지점을 WGS 84좌표로 변환해준다.

center_point의 좌표를 위도, 경도 컬럼으로 분리하여주면 끝
import geopandas as gpd
# 서울시 법정동 경계 데이터 불러오기
dong_boundary = gpd.read_file('/Users/sookyeong/Documents/내배캠/팀프로젝트/project5_final/emd.shp', encoding='cp949')
# CRS 설정
dong_boundary.crs = 'EPSG:5179'
# 중심점 좌표 계산
dong_boundary['center_point'] = dong_boundary['geometry'].centroid
# 좌표를 WGS 84 좌표계로 변환
dong_boundary['geometry'] = dong_boundary['geometry'].to_crs(epsg=4326)
dong_boundary['center_point'] = dong_boundary['center_point'].to_crs(epsg=4326)
#위도, 경도 컬럼 생성
dong_boundary['위도'] = dong_boundary['center_point'].y
dong_boundary['경도'] = dong_boundary['center_point'].x
#필요한 컬럼 남기기
dong_boundary = dong_boundary.drop(columns = ['geometry', 'center_point'])
