一 坐标介绍
1 地球坐标:
GPS、WGS84,地理坐标系统。
2 火星坐标:
GCJ-02,投影坐标系统,中国自己在WGS84基础上加密而成。
3 地球坐标:
BD-09,投影坐标系统,百度地图使用。
二 坐标转换
import math
pi = 3.14159265358979324;
a = 6378245.0;
ee = 0.00669342162296594323;
x_pi = 3.14159265358979324 * 3000.0 / 180.0;
def transformLat(x,y):
ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * math.sqrt(abs(x))
ret += (20.0 * math.sin(6.0 * x * pi) + 20.0 * math.sin(2.0 * x * pi)) * 2.0 / 3.0
ret += (20.0 * math.sin(y * pi) + 40.0 * math.sin(y / 3.0 * pi)) * 2.0 / 3.0
ret += (160.0 * math.sin(y / 12.0 * pi) + 320 * math.sin(y * pi / 30.0)) * 2.0 / 3.0
return ret
def transformLon(x,y):
ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * math.sqrt(abs(x))
ret += (20.0 * math.sin(6.0 * x * pi) + 20.0 * math.sin(2.0 * x * pi)) * 2.0 / 3.0
ret += (20.0 * math.sin(x * pi) + 40.0 * math.sin(x / 3.0 * pi)) * 2.0 / 3.0
ret += (150.0 * math.sin(x / 12.0 * pi) + 300.0 * math.sin(x / 30.0 * pi)) * 2.0 / 3.0
return ret
'''
* 地球坐标转换为火星坐标
*
* @param wgLat 地球坐标
* @param wgLon
*
* mglat,mglon 火星坐标
'''
def transform2Mars(wgLat,wgLon):
dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
radLat = wgLat / 180.0 * pi;
magic = math.sin(radLat);
magic = 1 - ee * magic * magic;
sqrtMagic = math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
dLon = (dLon * 180.0) / (a / sqrtMagic * math.cos(radLat) * pi);
mgLat = wgLat + dLat;
mgLon = wgLon + dLon;
return mgLat,mgLon
'''
* 百度转火星
* @param bd_lat
* @param bd_lon
'''
def bd_decrypt(bd_lat,bd_lon):
x = bd_lon - 0.0065
y = bd_lat - 0.006
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);
gg_lon = z * math.cos(theta);
gg_lat = z * math.sin(theta);
return gg_lat,gg_lon
ps:使用过,误差很小,可以接受。