import pandas as pd
import geopandas as gpd
import pyproj
from fiona.crs import from_epsg
import os
# dw 연결
import ibm_db_dbi
# Setting
conn = ibm_db_dbi.connect("DRIVER={IBM DB2 ODBC DRIVER}; Database='db이름'; Hostname=hostip입력; Port=portnumber입력; PROTOCOL=TCPIP; UID=userid입력; PWD=비밀번호입력", "", "")
query_biz = '''
쿼리
;
'''
# Sql
df_dw = pd.read_sql( query_biz, conn)
# 컬럼명 소문자 변환
df_dw.columns = df_dw.columns.str.lower()
##### convert katec UTM-K to geometry
df_point = gpd.points_from_xy(df_dw.str_xcoor, df_dw.str_ycoor)
coulumns = ['cd',"nm","city"]
df_cd = gpd.GeoDataFrame(df_dw[coulumns], geometry=df_point,
crs='+proj=tmerc +lat_0=38 +lon_0=128 +k=0.9999 +x_0=400000 +y_0=600000 +ellps=bessel +units=m +no_defs +towgs84=-115.80,474.99,674.11,1.16,-2.31,-1.63,6.43')
##### 'UTM-K' => 'WGS84' 변환
df_cd = df_cd.to_crs(epsg = 4326).reset_index(drop=True)
df_cd['latitude'] = [re.findall('\d+\.\d+', str(df_cd['geometry'][x]))[1] for x in range(len(df_cd))]
df_cd['longitude'] = [re.findall('\d+\.\d+', str(df_cd['geometry'][x]))[0] for x in range(len(df_cd))]
df_cd["latitude_f"]=df_cd["latitude"].apply(pd.to_numeric)
df_cd["longitude_f"]=df_cd["longitude"].apply(pd.to_numeric)
'언어 꿀Tip > Python 꿀tip!' 카테고리의 다른 글
07_01_56. dropna 함수 (결측치 제거) (0) | 2021.06.23 |
---|---|
07_01_55. 날짜, 시간 함수 strptime , strftime (0) | 2021.06.22 |
07_01_53. enumerate 함수 이용한 for 문 (0) | 2021.06.17 |
07_01_50. DataFrame의 문자열 칼럼을 분할하여 일부분으로 새로운 칼럼 만들기 (0) | 2021.06.17 |
07_01_49. timeseries 그래프에 linear regression trend line 추가 (0) | 2021.06.17 |