代码分析Python地图坐标转换
作者:laozhang 发布时间:2022-01-15 19:50:48
标签:Python,地图坐标
最近做项目正好需要坐标的转换
各地图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 csv
import string
import time
import math
#系数常量
a = 6378245.0
ee = 0.00669342162296594323
x_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 gcj
def 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 bd2
def 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 bd
def 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("转换成功")
0
投稿
猜你喜欢
- HTML文件 一、 设置编码UTF-8对于中文网页需要使用<meta charset="utf-8">声明编
- 前言我们在使用vue-cli启动项目的时候npm run dev便可以启动我们的项目了,通常我们的请求地址是以localhost:8080来
- 本文为大家解析了python实现4名牌手洗牌发牌的问题,供大家参考,具体内容如下编写程序, 4名牌手打牌,计算机随机将52张牌(不含大小鬼)
- 题目描述给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它
- matplotlib是功能十分强大的绘制二维图形的Python模块,它用Python语言实现了MATLAB画图函数的易用性,同时又有非常强大
- mysqladmin 工具的使用格式:mysqladmin [option] command [command option] comman
- 1. Scrapy简介Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。 可以应用在包括数据挖掘,信息处理或存储历史数据等
- 【简介】django-admin.py是Django的一个用于管理任务的命令行工具。本文将描述它的大概用法。另外,在每一个Django pr
- 项目我采用了三层结构,我把LINQ的映射文件放到了DAL这个层中,映射文件自动由VS2008生成,在原来的机器上一直正常,一点问题都没有,当
- 在Mac OS上安装redis首先是安装,它会默认安装到/usr/local/bin下cd /tmpwget http://redis.go
- 目录房价数据分析数据简单清洗各区均价分析全市二手房装修程度分析各区二手房数量所占比比例热门户型均价分析总结房价数据分析数据简单清洗data.
- 以下方案皆为引用,仅供参考。方案一:1.先声明一下,这种解决方法适用于任何版本的永久破解启动不了的情况(包括:2019版本的)2.下面直接切
- 有时候要通过asp代码在数据库中创建表和列,下面的就是这些操作的函数。1.检测表是否存在tbName 检测的表的名称dbTp 数据库的类型1
- 本文介绍基于Python语言中gdal模块,对遥感影像数据进行栅格读取与计算,同时基于QA波段对像元加以筛选、掩膜的操作。本文所要实现的需求
- 今天,由于工作需要,我在自己的电脑上配置了Mysql5环境,同时安装了一个phpMyAdmin管理工具,安装完成后,发现在phpMyAdmi
- 简介有兴趣可以看看: 解释性语言+动态类型语言+强类型语言交互模式:(主要拿来试验,可以试试 ipython)$python>>
- python程序结构python“一切皆对象”,这是接触python听到最多的总结了。在python中最基层的单位应该就是对象了,对象需要靠
- 浏览器的刷新是指重复上一次向服务器发送的请求,而asp.net的服务器控件的事件都是通过postback机制向服务器发送请求的。所以,当你点
- JS提供两个截取字符串的方法,分别是:slice()和substring()slice和substring都可以接受一个或两个参数,第1个参
- 前言vue是现在很火的一个前端MVVM框架,它以数据驱动和组件化的思想构建,与angular和react并称前端三大框架。相比angular