import math
import os
import folium
PI = 3.14159265358979324
ax = 6378245.0
ee = 0.00669342162296594323
x_pi = 52.3598775598298873
def outofChina(lat, lon):
if (lon < 72.004 or lon > 137.8347) and (lat < 0.8293 or lat > 55.8271):
return True
else:
return False
def mars_to_baidu(longtide, latitude):
baidu_long = 0.0
baidu_lati = 0.0
z = math.sqrt(longtide*longtide + latitude*latitude) + 0.00002 * math.sin(latitude * x_pi)
theta = math.atan2(latitude, longtide) + 0.000003 * math.cos(longtide * x_pi)
baidu_long = z * math.cos(theta) + 0.0065
baidu_lati = z * math.sin(theta) + 0.006
return baidu_long, baidu_lati
def transformLat(x , y):
ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * math.sqrt(math.fabs(x))
ret += (20.0 * math.sin(6.0 * x * PI) + 20.0 * math.sin(2.0 * x * PI)) * 2.0 / 3.0
ret += (20.0 * math.sin(y * PI) + 40.0 * math.sin(y / 3.0 * PI)) * 2.0 / 3.0
ret += (160.0 * math.sin(y / 12.0 * PI) + 320.0 * math.sin(y * PI / 30.0)) * 2.0 / 3.0
return ret
def transformLon(x, y):
ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * math.sqrt(math.fabs(x))
ret += (20.0 * math.sin(6.0 * x * PI) + 20.0 * math.sin(2.0 * x * PI)) * 2.0 / 3.0
ret += (20.0 * math.sin(x * PI) + 40.0 * math.sin(x / 3.0 * PI)) * 2.0 / 3.0
ret += (150.0 * math.sin(x / 12.0 * PI) + 300.0 * math.sin(x / 30.0 * PI)) * 2.0 / 3.0
return ret
def transform_both_all(wgLat, wgLon):
trans_long = 0.0
trans_lati = 0.0
if outofChina(wgLat, wgLon):
trans_long = wgLon
trans_lati = wgLat
return 0, 0
dLat = transformLat(wgLon - 105.0, wgLat - 35.0)
dLon = transformLon(wgLon - 105.0, wgLat - 35.0)
radLat = wgLat / 180.0 * PI
magic = math.sin(radLat)
magic_2 = 1 - ee * magic * magic
sqrtMagic = math.sqrt(magic_2)
dLat_2 = (dLat * 180.0) / ((ax * (1 - ee)) / (magic_2 * sqrtMagic) * PI)
dLon_2 = (dLon * 180.0) / (ax / sqrtMagic * math.cos(radLat) * PI)
trans_lati = wgLat + dLat_2
trans_long = wgLon + dLon_2
return trans_long, trans_lati
def ConvertDegreesToRadians(degrees):
return degrees * PI / 180.0
def ConvertRadiansToDegrees(radian):
return radian * 180.0 / PI
def HaveSin(theta):
val = math.sin(theta / 2)
return val * val
def Long_Lati_Distance(lat1, long1, lat2, long2):
earth_radius = 6371.0
temp_lat_1 = ConvertDegreesToRadians(lat1)
temp_lon_1 = ConvertDegreesToRadians(long1)
temp_lat_2 = ConvertDegreesToRadians(lat2)
temp_lon_2 = ConvertDegreesToRadians(long2)
vLon = math.fabs(temp_lon_1 - temp_lon_2)
vLat = math.fabs(temp_lat_1-temp_lat_2)
high = HaveSin(vLat) + math.cos(temp_lat_1) * math.cos(temp_lat_2) * HaveSin(vLon)
distance = 2 * earth_radius * math.asin(math.sqrt(high))
return distance
def create_float_value(tmpfloat):
intPart = 0.0
fractPart = 0.0
fractPart, intPart = math.modf(tmpfloat)
#print(fractPart, intPart)
tempVal1 = int(intPart / 100)
tempVal2 = int(intPart % 100)
tempVal3 = tempVal2 + fractPart
tempVal4 = tempVal3 / 60.0
tempVal5 = tempVal1 + tempVal4
return tempVal5
'''
point_longitude = 114.39250
point_latitude = 30.468819
point_long_2 = 114.392059
point_lati_2 = 30.468697
temp_long_1 , templati_1 = transform_both_all(point_latitude, point_longitude)
temp_long , templati = mars_to_baidu(temp_long_1, templati_1)
temp_long_2 , templati_2 = transform_both_all(point_lati_2,point_long_2)
temp_long2 , templati2 = mars_to_baidu(temp_long_2, templati_2)
print(temp_long, templati)
print(temp_long2, templati2)
distance_val = Long_Lati_Distance(templati, temp_long, templati2, temp_long2)
print(distance_val)
'''
fp = open("gps.txt", 'r')
lines = fp.readlines()
line_num = 0
longitude_list = []
latitude_list = []
map_info = folium.Map(location=[30.2813, 114.2352], zoom_start=12, control_scale=True)
for line in lines:
if line[:6] == '$GNGLL':
line_num += 1
#print(line)
longitude_list.append(create_float_value(float(line.split(',')[3])))
latitude_list.append(create_float_value(float(line.split(',')[1])))
'''
if line_num == 1:
longitude1 = line.split(',')[3]
latitude1 = line.split(',')[1]
elif line_num == 2:
longitude2 = line.split(',')[3]
latitude2 = line.split(',')[1]
line_num = 0
if line_num == 0:
longitude_1 = create_float_value(float(longitude1))
latitude_1 = create_float_value(float(latitude1))
longitude_2 = create_float_value(float(longitude2))
latitude_2 = create_float_value(float(latitude2))
temp_long_1, templati_1 = transform_both_all(latitude_1, longitude_1)
temp_long, templati = mars_to_baidu(temp_long_1, templati_1)
temp_long_2, templati_2 = transform_both_all(latitude_2, longitude_2)
temp_long2, templati2 = mars_to_baidu(temp_long_2, templati_2)
distance_val = Long_Lati_Distance(templati, temp_long, templati2, temp_long2)*1000
print(distance_val)
'''
#print(longitude, latitude)
else:
continue
print(longitude_list)
print(latitude_list)
for longitude, latitude in zip(longitude_list, latitude_list):
folium.Circle((latitude, longitude), radius=7, color='yellow', fill=True,
fill_color='red', fill_opacity=0.7).add_to(map_info)
lenth = len(longitude_list)
for i in range(lenth):
folium.Marker(location=[latitude_list[i], longitude_list[i]], popup='点',
icon=folium.Icon(icon='cloud')).add_to(map_info)
map_info.add_child(folium.LatLngPopup())
map_info.save('gps.html')
没有合适的资源?快使用搜索试试~ 我知道了~
python提取gps数据,利用folium库生成位置分布图,包含百度坐标转换以及两点距离换算函数.zip
共1个文件
py:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 78 浏览量
2023-05-12
22:55:20
上传
评论
收藏 2KB ZIP 举报
温馨提示
根据GPS坐标信息得到设备分布位置,以及根据相邻位置坐标获取设备移动距离,这里使用python对GPS模块输出的位置坐标信息进行提取,并使用python库对坐标位置进行描点,生成设备位置分布图,根据前后两点的坐标计算出设备移动的距离
资源推荐
资源详情
资源评论
收起资源包目录
python提取gps数据,利用folium库生成位置分布图,包含百度坐标转换以及两点距离换算函数.zip (1个子文件)
gps_convert.py 6KB
共 1 条
- 1
资源评论
- cc2530f2562024-01-04终于找到了超赞的宝藏资源,果断冲冲冲,支持!
小风飞子
- 粉丝: 322
- 资源: 1500
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功