坐标转换、地球转火星、百度转火星(python版)

一 坐标介绍

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:使用过,误差很小,可以接受。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值