用python 來實現經緯度的測算與輸出

2021-09-30 01:54:34 字數 1370 閱讀 6693

本文採用高德地圖地理標識規範

首先匯入兩個分析包,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))

elif j == 0:

res1[j][0] = x1 + x

res1[j][1] = y1 + y

else:

df.loc[i,'res1'] = str(res1)

df.to_excel('經緯度結果表.xlsx',index=false,sheet_name = 'df1')

ThinkPHP實現經緯度範圍查詢

thinkphp實現附近範圍的查詢,如附近的人和附近 之類。首先,要定位使用者的經緯度。客戶端定位的方法可以使用地圖api或者用html5瀏覽器定位 比較不穩定而且不會太精確 然後,將當前經緯度,和需要搜尋的距離範圍,計算乙個經緯度範圍,這個範圍就是 附近 計算這個 附近 的示例如下 param l...

python實現 經緯度的 各GIS座標系轉換

這裡是gis座標的單點轉換.下面是利用python反射機制實現的gis座標轉換類.精度不是很完美但一般也夠用啦.coding utf 8 import math,re class gistransform object gis座標轉換類 def init self,old gis name,new ...

MATLAB程式實現經緯度轉換成平面座標

近期搜了下經緯度座標轉換成直角座標的程式和原理啥的,哎,真難啊,其實道理都懂吧,下面直接貼 主要是加了個for迴圈而言,優化輸出效果。matlab程式實現經緯度轉換成平面爾座標 m pi 3.14159265358979323846 l 6381372 m pi 2 地球周長 w l 平面展開後,x...