国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

代碼分析Python地圖坐標轉換

2020-02-22 23:10:34
字體:
來源:轉載
供稿:網友

最近做項目正好需要坐標的轉換

各地圖API坐標系統比較與轉換; WGS84坐標系:即地球坐標系,國際上通用的坐標系。設備一般包含GPS芯片或者北斗芯片獲取的經緯度為WGS84地理坐標系, 谷歌地圖采用的是WGS84地理坐標系(中國范圍除外); GCJ02坐標系:即火星坐標系,是由中國國家測繪局制訂的地理信息系統的坐標系統。由WGS84坐標系經加密后的坐標系。 谷歌中國地圖和搜搜中國地圖采用的是GCJ02地理坐標系; BD09坐標系:即百度坐標系,GCJ02坐標系經加密后的坐標系; 搜狗坐標系、圖吧坐標系等,估計也是在GCJ02基礎上加密而成的.

然后在csv中將其轉化。

最后再在百度地圖API上進行檢驗成功

#http://bbs.lbsyun.baidu.com/forum.php?mod=viewthread&tid=10923#代碼原地址import csvimport stringimport timeimport math#系數常量a = 6378245.0ee = 0.00669342162296594323x_pi = 3.14159265358979324 * 3000.0 / 180.0;#轉換經度def transformLat(lat,lon): ret = -100.0 + 2.0 * lat + 3.0 * lon + 0.2 * lon * lon + 0.1 * lat * lon +0.2 * math.sqrt(abs(lat)) ret += (20.0 * math.sin(6.0 * lat * math.pi) + 20.0 * math.sin(2.0 * lat * math.pi)) * 2.0 / 3.0 ret += (20.0 * math.sin(lon * math.pi) + 40.0 * math.sin(lon / 3.0 * math.pi)) * 2.0 / 3.0 ret += (160.0 * math.sin(lon / 12.0 * math.pi) + 320 * math.sin(lon * math.pi / 30.0)) * 2.0 / 3.0 return ret#轉換緯度def transformLon(lat,lon): ret = 300.0 + lat + 2.0 * lon + 0.1 * lat * lat + 0.1 * lat * lon + 0.1 * math.sqrt(abs(lat)) ret += (20.0 * math.sin(6.0 * lat * math.pi) + 20.0 * math.sin(2.0 * lat * math.pi)) * 2.0 / 3.0 ret += (20.0 * math.sin(lat * math.pi) + 40.0 * math.sin(lat / 3.0 * math.pi)) * 2.0 / 3.0 ret += (150.0 * math.sin(lat / 12.0 * math.pi) + 300.0 * math.sin(lat / 30.0 * math.pi)) * 2.0 / 3.0 return ret#Wgs transform to gcjdef wgs2gcj(lat,lon): dLat = transformLat(lon - 105.0, lat - 35.0) dLon = transformLon(lon - 105.0, lat - 35.0) radLat = lat / 180.0 * math.pi magic = math.sin(radLat) magic = 1 - ee * magic * magic sqrtMagic = math.sqrt(magic) dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * math.pi) dLon = (dLon * 180.0) / (a / sqrtMagic * math.cos(radLat) * math.pi) mgLat = lat + dLat mgLon = lon + dLon loc=[mgLat,mgLon] return loc#gcj transform to bd2def gcj2bd(lat,lon): x=lon y=lat 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) bd_lon = z * math.cos(theta) + 0.0065 bd_lat = z * math.sin(theta) + 0.006 bdpoint = [bd_lon,bd_lat] return bdpoint#wgs transform to bddef wgs2bd(lat,lon): wgs_to_gcj = wgs2gcj(lat,lon) gcj_to_bd = gcj2bd(wgs_to_gcj[0], wgs_to_gcj[1]) return gcj_to_bd;for i in range (3,4): n = str('2017.040'+ str(i)+'.csv') m = str('2017040' + str(i)+'.csv') csvfile = open(m,'w',encoding='UTF-8',newline='') nodes = csv.writer(csvfile) nodes.writerow(['md5','content','phone','conntime','recitime','lng','lat']) l=[] with open(n,newline='',encoding='UTF-8') as f:  reader = csv.DictReader(f)  for row in reader:   if row['md5'] == 'md5':    continue   else:    y=float(row['lng'])    x=float(row['lat'])    loc=wgs2bd(x,y)    l.append([row['md5'],row['content'],row['phone'],row['conntime'],row['recitime'],loc[0],loc[1]]) nodes.writerows(l) csvfile.close() print("轉換成功")            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 卢龙县| 阆中市| 诸城市| 邹平县| 谢通门县| 威信县| 双鸭山市| 当阳市| 承德市| 衡山县| 宝兴县| 平顺县| 田林县| 陆丰市| 犍为县| 齐齐哈尔市| 金沙县| 那曲县| 新郑市| 宁晋县| 怀集县| 克什克腾旗| 方山县| 晋宁县| 平罗县| 黄浦区| 汾阳市| 客服| 钟山县| 潢川县| 六盘水市| 中牟县| 浑源县| 榕江县| 汤原县| 三都| 云安县| 高雄市| 沧州市| 金山区| 喀喇沁旗|