python计算指定两点经纬度之间的距离,python经纬度,下面代码用来计算两个GP
python计算指定两点经纬度之间的距离,python经纬度,下面代码用来计算两个GP
下面代码用来计算两个GPS点之间的直线距离,以及两点之间的垂直距离和水平距离。
#-------------------------------------------------------------------------------#Copyright (C) <2011> by <James Dyson>#Contact [email protected]#Python 3#Permission is hereby granted, free of charge, to any person obtaining a copy#of this code to use this code without restriction, including without limitation #the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or #sell copies of the code, and to permit persons to whom the code is#furnished to do so, subject to the following conditions:#The above copyright notice and this permission notice shall be included in#all copies or substantial portions of the code.#THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,#OUT OF OR IN CONNECTION WITH THE CODE OR THE USE OR OTHER DEALINGS IN#THE CODE.#-------------------------------------------------------------------------------from math import *#Two Example GPS Locationslat1 = 53.32055555555556lat2 = 53.31861111111111lon1 = -1.7297222222222221lon2 = -1.6997222222222223Aaltitude = 2000Oppsite = 20000#Haversine Formuala to find vertical angle and distancelon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])dlon = lon2 - lon1dlat = lat2 - lat1a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2c = 2 * atan2(sqrt(a), sqrt(1-a))Base = 6371 * c#Horisontal Bearingdef calcBearing(lat1, lon1, lat2, lon2): dLon = lon2 - lon1 y = sin(dLon) * cos(lat2) x = cos(lat1) * sin(lat2) \ - sin(lat1) * cos(lat2) * cos(dLon) return atan2(y, x)Bearing = calcBearing(lat1, lon1, lat2, lon2)Bearing = degrees(Bearing)Base2 = Base * 1000distance = Base * 2 + Oppsite * 2 / 2Caltitude = Oppsite - Aaltitude#Convertion from radians to decimalsa = Oppsite/Baseb = atan(a)c = degrees(b)#Convert meters into Kilometersdistance = distance / 1000#Output the dataprint("---------------------------------------")print(":::::Auto Aim Directional Anntenna:::::")print("---------------------------------------")print("Horizontial Distance:", Base,"km")print(" Vertical Distance:", distance,"km")print(" Vertical Bearing:",c)print(" Horizontial Bearing:",Bearing)print("---------------------------------------")input("Press <enter> to Exit")
如果你觉得这段代码有用,请顶一下,谢谢!
相关内容
- python urllib quote或者quote_plus 抛出keyError的解决方案,u
- python2.7将doc文件转换成文本文件(windows),python2.7do
- python二分法查找,python二分法,def binary_s
- python列表操作extend和append的区别演示代码,pythonextend
- Python压缩文件夹/解压缩zip文件,pythonzip,使用python自带
- python 使用psutil根据进程名获取PID,pythonpsutil,保存为.
- python写守护进程代码示例,python守护进程,下面是一个简
- 检测UDP端口是否开放,检测UDP端口开放,[Python]代码im
- python 各种解析xml包使用方法总结,pythonxml,使用python开
- python写日志的封装类,python日志封装,# encoding:u
评论关闭