用python 来实现经纬度的测算与输出

本文采用高德地图地理标识规范

首先导入两个分析包,math和pandas,如果有需要还有numpy,mathplotlib等常用数据分析包

import pandas as pd
import math

测算一经度和一纬度的距离

# 地球半径
r  = 12713.504 / 2
# 1纬度长
wd = (2 * math.pi * r) / 180
# 1经度长
jd = (5 * math.sin(math.atan2(x2-x1,y2-y1))) / (wd * math.cos(x))
图片来源百度图片
该图片来源于百度图片

读写原excel文件并输出

df = pd.read_excel('jwd.xlsx')
# df = df.head()
# make a new col
df['res1'] = df['a_road']
res1 = [[0,1]]


# get index
for i in range(df.iloc[:,0].size):
    x1 = df.latA[i]
    y1 = df.lngA[i]
    x2 = df.latB[i]
    y2 = df.lngB[i]
    # 通过三角函数进行求值
    # 1纬度 111km 
    # 1经度 111*cos纬度 km
    x  = (5 * math.cos(math.atan2(x2-x1,y2-y1))) / wd
    y  = (5 * math.sin(math.atan2(x2-x1,y2-y1))) / (wd * math.cos(x))
    #print(x,y)
    for j in range(0,int(df.distance[i] / 5) + 1):
        if j == int(df.distance[i] / 5):
            num = df.distance[i] % 5
            x  = (num * math.cos(math.atan2(x2-x1,y2-y1))) / wd
            y  = (num * math.sin(math.atan2(x2-x1,y2-y1))) / (wd * math.cos(x))
            res1.append([x2 - x,y2 - y])
        elif j == 0:
            res1[j][0] = x1 + x 
            res1[j][1] = y1 + y 
        else:
            res1.append([x1 + x * (j + 1),y1 + y * (j + 1)])
    df.loc[i,'res1'] = str(res1)

df.to_excel('经纬度结果表.xlsx',index=False,sheet_name = 'df1')

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

神芷迦蓝寺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值