本文采用高德地图地理标识规范
首先导入两个分析包,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')