一、百度与高德坐标系互换
百度坐标系:bd09
高德坐标系: gcj02
python
import math
# 坐标系转换:百度转高德,高德转百度
class CoordinateSystem:
@staticmethod
def bd09_to_gcj02(bd_lon, bd_lat):
'''
百度坐标系:bd09 转成高德坐标系 gcj02
Args:
bd_lon: 百度坐标系纬度
bd_lat: 百度坐标系经度
Return:
(高德坐标系纬度,高德坐标系经度)
'''
bd_lon = float(bd_lon)
bd_lat = float(bd_lat)
x = bd_lon - 0.0065
y = bd_lat - 0.006
z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * math.pi)
theta = math.atan2(y, x) - 0.000003 * math.cos(x * math.pi)
gcj_lon = z * math.cos(theta)
gcj_lat = z * math.sin(theta)
return gcj_lon, gcj_lat
@staticmethod
def gcj02_to_bd09(lon, lat):
'''
高德坐标系:gcj02 转成高德坐标系 bd09
Args:
lon: 高德坐标系纬度
lat: 高德坐标系经度
Return:
(高德坐标系纬度,高德坐标系经度)
'''
lon = float(lon)
lat = float(lat)
z = math.sqrt(lon * lon + lat * lat) + 0.00002 * math.sin(lat * math.pi)
theta = math.atan2(lat, lon) + 0.000003 * math.cos(lon * math.pi)
bd_lon = z * math.cos(theta) + 0.0065
bd_lat = z * math.sin(theta) + 0.006
return bd_lon, bd_lat
if __name__ == '__main__':
lon = 23.0534260666666
lat = 113.40712125
gd_lob,gd_lat = CoordinateSystem.bd09_to_gcj02(bd_lon=lon,bd_lat=lat)