Skip to content

Instantly share code, notes, and snippets.

@allieus
Last active June 25, 2022 18:10
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save allieus/1180051 to your computer and use it in GitHub Desktop.
Save allieus/1180051 to your computer and use it in GitHub Desktop.
wgs84/tm127/tm128/grs80/cyworld 간 좌표변환
'''
aero님께서 구현하신 구글/네이버/싸이월드/콩나물 좌표변환은 펄/자바스크립트로 되어있습니다.
펄/자바스크립트에 익숙지 않은지라, 수식을 파이썬으로 번역해보았습니다.
'''
from pyproj import Proj
from pyproj import transform
WGS84 = { 'proj':'latlong', 'datum':'WGS84', 'ellps':'WGS84', }
# conamul
TM127 = { 'proj':'tmerc', 'lat_0':'38N', 'lon_0':'127.0028902777777777776E',
'ellps':'bessel', 'x_0':'200000', 'y_0':'500000', 'k':'1.0',
'towgs84':'-146.43,507.89,681.46'}
# naver
TM128 = { 'proj':'tmerc', 'lat_0':'38N', 'lon_0':'128E', 'ellps':'bessel',
'x_0':'400000', 'y_0':'600000', 'k':'0.9999',
'towgs84':'-146.43,507.89,681.46'}
# GRS80(Geodetic Reference System 1980:측지 기준계 1980)의 타원체
GRS80 = { 'proj':'tmerc', 'lat_0':'38', 'lon_0':'127', 'k':1, 'x_0':200000,
'y_0':600000, 'ellps':'GRS80', 'units':'m' }
def wgs84_to_tm128(longitude, latitude):
return transform( Proj(**WGS84), Proj(**TM128), longitude, latitude )
def tm128_to_wgs84(x, y):
return transform( Proj(**TM128), Proj(**WGS84), x, y )
def wgs84_to_tm127(longitude, latitude):
return map(lambda x:2.5*x,
transform( Proj(**WGS84), Proj(**TM127), longitude, latitude ))
def tm127_to_wgs84(x, y):
return transform( Proj(**TM127), Proj(**WGS84), x/2.5, y/2.5 )
def grs80_to_wgs84(x, y):
return transform( Proj(**GRS80), Proj(**WGS84), x, y )
def wgs84_to_cyworld(longitude, latitude):
x_min = 4456260.72
y_min = 1161720.00
long_min = 123.78323
lat_min = 32.27345
max_grid_length = 112721.92
x = (longitude-long_min)*max_grid_length/3.1308 + x_min
y = (latitude-lat_min)*max_grid_length/3.1308 + y_min
return x, y
def cyworld_to_wgs84(x, y):
x_min = 4456260.72;
y_min = 1161720.00;
long_min = 123.78323;
lat_min = 32.27345;
max_grid_length = 112721.92;
longitude = long_min + (x-x_min)*3.1308 / max_grid_length;
latitude = lat_min + (y-y_min)*3.1308 / max_grid_length;
return longitude, latitude
@allieus
Copy link
Author

allieus commented Dec 27, 2014

added grs80
by scari - http://github.com/scari

@donghyeon-kim98
Copy link

donghyeon-kim98 commented Nov 19, 2020

정확도면에서 TM128의 towgs84 값이 빼는 게 더 정확도가 높은 거 같아서 코멘트 남깁니다 :)
덕분에 쉽게 변환코드 작성할 수 있었네요 감사합니다. 🙇‍♂️

tm128_to_wgs84(204614.000000, 417311.000000)
Out[3]: (125.82147136623257, 36.3365679077234)

wgs84_to_tm128(125.82147136623257, 36.3365679077234) 
Out[4]: (204614.0023616594, 417310.9955479153)

# TM128에서 towgs84 값을 빼고 했을 때
tm128_to_wgs84(204614.000000, 417311.000000)
Out[3]: (125.82345993053727, 36.33370569945053)

wgs84_to_tm128(125.82345993053727, 36.33370569945053) 
Out[4]: (204613.99999999933, 417311.00000000047)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment