資源簡(jiǎn)介
學(xué)習(xí)python加載百度、高德地圖過(guò)程中,通過(guò)百度提供的糾偏接口速度緩慢,制作軌跡回放時(shí)速度緩慢,百度過(guò)很多資源,只有C#版本的糾偏類,隨改為python3類,以供使用,已測(cè)試百度地圖效果標(biāo)點(diǎn)重合!

代碼片段和文件信息
import?math
x_PI?=?3.14159265358979324?*?3000.0?/?180.0
PI?=?3.1415926535897932384626
a?=?6378245.0
ee?=?0.00669342162296594323???
class?GpsConvert(object):
?
#????*?BD-09:百度坐標(biāo)系(百度地圖)
#????*?GCJ-02:火星坐標(biāo)系(谷歌中國(guó)地圖、高德地圖)
#????*?WGS84:地球坐標(biāo)系(國(guó)際通用坐標(biāo)系,谷歌地圖)
????def?__init__(self):
????????pass
????
#百度坐標(biāo)系轉(zhuǎn)火星坐標(biāo)系
????def?bd09togcj02(selfbd_lon?bd_lat):
????????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)
????????gcj_lon?=?z?*?math.cos(theta)
????????gcj_lat?=?z?*?math.sin(theta)
????????gcj?=?[?gcj_lon?gcj_lat?]//火星坐標(biāo)系值
???????#火星坐標(biāo)系轉(zhuǎn)wgs84
????????wgs?=?self.gcj02towgs84(gcj[0]?gcj[1])
????????return?wgs
#火星坐標(biāo)系轉(zhuǎn)wgs84
????def?gcj02towgs84(selfgcj_lon?gcj_lat):
????????if?(self.out_of_china(gcj_lon?gcj_lat)):
#????????????//不在國(guó)內(nèi),不進(jìn)行糾偏
????????????back?=?[?gcj_lon?gcj_lat?]
????????????return?back
????????else:
????????????dlon?=?transformlon(gcj_lon?-?105.0?gcj_lat?-?35.0)
????????????dlat?=?transformlat(gcj_lon?-?105.0?gcj_lat?-?35.0)
????????????radlat?=?gcj_lat?/?180.0?*?PI
????????????magic?=?math.sin(radlat)
????????????magic?=?1?-?ee?*?magic?*?magic
????????????sqrtmagic?=?math.sqrt(magic)
????????????dlon?=?(dlon?*?180.0)?/?(a?/?sqrtmagic?*?math.cos(radlat)?*?PI)
????????????dlat?=?(dlat?*?180.0)?/?((a?*?(1?-?ee))?/?(magic?*?sqrtmagic)?*?PI)
????????????mglon?=?gcj_lon?+?dlon
????????????mglat?=?gcj_lat?+?dlat
????????????wgs_lon?=?gcj_lon?*?2?-?mglon
????????????wgs_lat?=?gcj_lat?*?2?-?mglat
????????????wgs?=?[?wgs_lon?wgs_lat?]//wgs84坐標(biāo)系值
????????????return?wgs
?#???//火星坐標(biāo)系轉(zhuǎn)百度坐標(biāo)系
????def?gcj02tobd09(selfgcj_lon?gcj_lat):
????????z?=?math.sqrt(gcj_lon?*?gcj_lon?+?gcj_lat?*?gcj_lat)?+?0.00002?*?math.sin(gcj_lat?*?x_PI)
????????theta?=?math.atan2(gcj_lat?gcj_lon)?+?0.000003?*?math.cos(gcj_lon?*?x_PI)
????????bd_lon?=?z?*?math.cos(theta)?+?0.0065
????????bd_lat?=?z?*?math.sin(theta)?+?0.006
????????bd?=?[?bd_lon?bd_lat?]
????????return?bd
#????//wgs84轉(zhuǎn)火星坐標(biāo)系
????def?wgs84togcj02(selfwgs_lon?wgs_lat):
????????if?(self.out_of_china(wgs_lon?wgs_lat)):
????????????#//不在國(guó)內(nèi)
????????????back?=?[?wgs_lon?wgs_lat?]
????????????return?back
????????else:
????????????dwgs_lon?=?self.transformlon(wgs_lon?-?105.0?wgs_lat?-?35.0)
????????????dwgs_lat?=?self.transformlat(wgs_lon?-?105.0?wgs_lat?-?35.0)
????????????radwgs_lat?=?wgs_lat?/?180.0?*?PI
????????????magic?=?math.sin(radwgs_lat)
????????????magic?=?1?-?ee?*?magic?*?magic
????????????sqrtmagic?=?math.sqrt(magic)
????????????dwgs_lon?=?(dwgs_lon?*?180.0)?/?(a?/?sqrtmagic?*?math.cos(radwgs_lat)?*?PI)
????????????dwgs_lat?=?(dwgs_lat?*?180.0)?/?((a?*?(1?-?ee))?/?(magic?*?sqrtmagic)?*?PI)
????????????gcj_lon?=?wgs_lon?+?dwgs_lon
????????????gcj_lat?=?wgs_lat?+?dwgs_lat
????????????gcj?=?[?gcj_lon?gcj_lat?]
????????????return?gcj
????def?transformlon(selflo
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????1214??2018-04-25?10:25??test.py
?????文件????????4315??2018-04-25?10:24??GpsConvert.py
評(píng)論
共有 條評(píng)論