坐标点转换

看群友讨论顺便记录下。

#-*- utf-8 -*-
import math
#114.29536896,22.67160804 114.29521308,22.67150796 114.29511696,22.67172198 114.29529084,22.67178804 114.29536896,22.67160804
lis = ["114.29496792,22.67057799 114.29503812,22.67053497 114.29498592,22.67045901 114.29493408,22.67049096 114.29490708,22.67050896 114.29491608,22.67053002 114.294951,22.67057196 114.29496,22.67056503 114.29496792,22.67057799","114.294456,22.66987401 114.29450784,22.66994997 114.29453412,22.66993503 114.29454312,22.66993098 114.29455104,22.66992603 114.29459496,22.66990002 114.29460288,22.66989597 114.29458596,22.66986996 114.29457696,22.66987401 114.29453412,22.66982397 114.29447292,22.66986303 114.294456,22.66987401","114.29463816,22.66994799 114.29461188,22.66990902 114.29460288,22.66991604 114.29452512,22.66996302 114.29456004,22.67001297 114.29454312,22.67001999 114.29456904,22.670046 114.29457696,22.67004204 114.29459496,22.670028 114.29462088,22.67001504 114.29465508,22.669992 114.29466408,22.66998498 114.29463816,22.66994799"]
for li in lis:
    location = li.split(' ')
    print ("******************************")
    for loc in location:
        lo = loc.split(',')
        lon,lat =  float(lo[0]),float(lo[1])
        lon = lon * math.pi/180
        lat = lat * math.pi/180
        bo = 30 * math.pi/180
        a = 6378137
        b = 6356752.3142
        e = math.sqrt(1- (b / a) * (b / a))
        e2 = math.sqrt((a / b) * (a / b) -1)
        CosB0 = math.cos(bo)
        N = (a * a / b) / math.sqrt(1+ e2 * e2 * CosB0 * CosB0)
        k = N * CosB0
        pi = math.pi
        sinb = math.sin(lat)
        tan = math.tan(pi/4+lat/2)
        E = math.pow((1- e * sinb) / (1+ e * sinb), e /2)
        xx = tan * E
        xc = k * math.log(xx)
        yc = k * lon
        print('['+str(yc) +','+str(xc)+'],')

posted @ 2018-10-23 17:22  公众号python学习开发  阅读(900)  评论(0编辑  收藏  举报