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")

如果你觉得这段代码有用,请顶一下,谢谢!

评论关闭