python實(shí)現(xiàn)兩個(gè)經(jīng)緯度點(diǎn)之間的距離和方位角的方法
最近做有關(guān)GPS軌跡上有關(guān)的東西,花費(fèi)心思較多,對(duì)兩個(gè)常用的函數(shù)總結(jié)一下,求距離和求方位角,比較精確,歡迎交流!
1. 求兩個(gè)經(jīng)緯點(diǎn)的方位角,P0(latA, lonA), P1(latB, lonB)(很多博客寫的不是很好,這里總結(jié)一下)
def getDegree(latA, lonA, latB, lonB):
"""
Args:
point p1(latA, lonA)
point p2(latB, lonB)
Returns:
bearing between the two GPS points,
default: the basis of heading direction is north
"""
radLatA = radians(latA)
radLonA = radians(lonA)
radLatB = radians(latB)
radLonB = radians(lonB)
dLon = radLonB - radLonA
y = sin(dLon) * cos(radLatB)
x = cos(radLatA) * sin(radLatB) - sin(radLatA) * cos(radLatB) * cos(dLon)
brng = degrees(atan2(y, x))
brng = (brng + 360) % 360
return brng
2. 求兩個(gè)經(jīng)緯點(diǎn)的距離函數(shù):P0(latA, lonA), P1(latB, lonB)
def getDistance(latA, lonA, latB, lonB): ra = 6378140 # radius of equator: meter rb = 6356755 # radius of polar: meter flatten = (ra - rb) / ra # Partial rate of the earth # change angle to radians radLatA = radians(latA) radLonA = radians(lonA) radLatB = radians(latB) radLonB = radians(lonB) pA = atan(rb / ra * tan(radLatA)) pB = atan(rb / ra * tan(radLatB)) x = acos(sin(pA) * sin(pB) + cos(pA) * cos(pB) * cos(radLonA - radLonB)) c1 = (sin(x) - x) * (sin(pA) + sin(pB))**2 / cos(x / 2)**2 c2 = (sin(x) + x) * (sin(pA) - sin(pB))**2 / sin(x / 2)**2 dr = flatten / 8 * (c1 - c2) distance = ra * (x + dr) return distance
以上這篇python實(shí)現(xiàn)兩個(gè)經(jīng)緯度點(diǎn)之間的距離和方位角的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python基礎(chǔ)while循環(huán)及if判斷的實(shí)例講解
下面小編就為大家?guī)硪黄猵ython基礎(chǔ)while循環(huán)及if判斷的實(shí)例講解。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
Python?EasyDict庫以屬性方式訪問字典元素(無需使用方括號(hào)和鍵)
在Python中,字典(dict)是一種常用的數(shù)據(jù)結(jié)構(gòu),用于存儲(chǔ)鍵值對(duì),然而,有時(shí)候我們希望以屬性的方式訪問字典中的元素,而無需使用方括號(hào)和鍵,這就是EasyDict庫的用武之地,本文將深入介紹EasyDict庫,展示其強(qiáng)大的功能和如何通過示例代碼更好地利用它2023-12-12
python庫geopandas讀取寫入空間數(shù)據(jù)及繪圖實(shí)例探索
這篇文章主要為大家介紹了python庫geopandas讀取寫入空間數(shù)據(jù)及繪圖實(shí)例探索,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>2024-02-02
Python實(shí)現(xiàn)清除文件夾中重復(fù)視頻
本文將利用Python中的os、hashlib、shutil模塊實(shí)現(xiàn)對(duì)文件夾中的重復(fù)視頻進(jìn)行清除,實(shí)現(xiàn)文件夾中無重復(fù)文件情況發(fā)生,需要的可以參考一下2022-05-05
Python中.join()和os.path.join()兩個(gè)函數(shù)的用法詳解
join()是連接字符串?dāng)?shù)組而os.path.join()是將多個(gè)路徑組合后返回。接下來通過本文重點(diǎn)給大家介紹Python中.join()和os.path.join()兩個(gè)函數(shù)的用法,感興趣的朋友一起看看吧2018-06-06
Python實(shí)現(xiàn)帶參數(shù)與不帶參數(shù)的多重繼承示例
這篇文章主要介紹了Python實(shí)現(xiàn)帶參數(shù)與不帶參數(shù)的多重繼承,結(jié)合具體實(shí)例形式對(duì)比分析了Python實(shí)現(xiàn)帶參數(shù)與不帶參數(shù)的多重繼承相關(guān)操作技巧,需要的朋友可以參考下2018-01-01

