一、三大坐标系
- WGS84坐标系:即地球坐标系,国际上通用的坐标系。
- GCJ02坐标系:即火星坐标系,WGS84坐标系经加密后的坐标系。
- BD09坐标系:即百度坐标系,GCJ02坐标系经加密后的坐标系。
二、纠偏代码
之前做公交路线地图显示,需要根据每路公交车站点的经纬度在地图上标注该站点,所以为了方便起见我将每一路车的经纬度作为一个List进行纠偏处理的而不是单个坐标对,这样处理也比较实用。由于数据是从网络上爬取下来的,List里面的每一个元素都是字符串,为了在处理时方便运算,我把他们进行了处理变成数值类型。代码如下。
import json
import urllib
import math
import numpy
from numpy.core import double
x_pi = 3.14159265358979324 * 3000.0 / 180.0
pi = 3.1415926535897932384626 # π
a = 6378245.0 # 长半轴
ee = 0.00669342162296594323 # 偏心率平方
class Geocoding:
def __init__(self, api_key):
self.api_key = api_key
def geocode(self, address):
"""
利用高德geocoding服务解析地址获取位置坐标
:param address:需要解析的地址
:return:
"""
geocoding = {
's': 'rsv3',
'key': self.api_key,
'city': '全国',
'address': address}
geocoding = urllib.urlencode(geocoding)
ret = urllib.urlopen("%s?%s" % ("http://restapi.amap.com/v3/geocode/geo", geocoding))
if ret.getcode() == 200:
res = ret.read()
json_obj = json.loads(res)
if json_obj['status'] == '1' and int(json_obj['count']) >= 1:
geocodes = json_obj['geocodes'][0]
lng = float(geocodes.get('location').split(',')[0])
lat = float(geocodes.get('location').split(',')[1])
return [lng, lat]
else:
return None
else:
return None
def substring(lng,lat):
#转为数值类型
tmp_x = []
tmp_y = []
for n in lng:
tmp_x.append(float(n))
lng = tmp_x;
for m in lat:
tmp_y.append(float(m))
lat = tmp_y;
return lng,lat
def gcj02_to_bd09(lng, lat)