火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法Python版本


# -*- coding: utf-8 -*-
import math
x_pi = 3.14159265358979324 * 3000.0 / 180.0
def bd_encrypt(gg):
    x = gg["gg_lon"]
    y = gg["gg_lat"]
    z = math.sqrt(x * x + y * y) + 0.00002 * math.sin(y * x_pi)
    theta = math.atan2(y, x) + 0.000003 * math.cos(x * x_pi)  
    bd_lon = z * math.cos(theta) + 0.0065 
    bd_lat = z * math.sin(theta) + 0.006
    return {"bd_lon":bd_lon, "bd_lat":bd_lat}

def bd_decrypt(bd):
    x = bd["bd_lon"] - 0.0065
    y = bd["bd_lat"] - 0.006;  
    z = sqrt(x * x + y * y) - 0.00002 * sin(y * x_pi);  
    theta = atan2(y, x) - 0.000003 * cos(x * x_pi);  
    gg_lon = z * cos(theta);
    gg_lat = z * sin(theta);
    return {"gg_lon":gg_lon, "gg_lat":gg_lat}

参考

  1. http://www.cnblogs.com/Tangf/archive/2012/09/16/2687236.html
  2. http://blog.woodbunny.com/post-68.html
  3. http://www.biaodianfu.com/coordinate-system.html

你可能感兴趣的:(百度坐标系,火星坐标系)