Python realizes the distance and azimuth between two latitude and longitude points

Source: Internet
Author: User
Tags sin

from:http://blog.csdn.net/zhuqiuhui/article/details/53180395

1. Find the azimuth of two latitude and longitude points, P0 (LatA, Lona), P1 (LATB, lonb) (many blogs do not write very well, summarize here)

    def getdegree (LatA, Lona, LATB, lonb): "" "         Args: Point             P1 (LatA, Lona) point             P2 (LATB, lonb)         Returns :             bearing between the "GPS points,             default:the basis of heading direction is" ""          radlata = Radia NS (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 +)%          return brng  

2. Find the distance function of two latitude and longitude points: 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 = Radi Ans (latA)          Radlona = radians (lona)          RADLATB = radians (LATB)          radlonb = radians (lonb)                PA = Atan (Rb/ra * t An (radlata))          PB = Atan (Rb/ra * TAN (RADLATB))          x = ACOs (sin (PA) * sin (pb) + cos (PA) * cos (PB) * cos (radlona-ra DLONB)          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 realizes the distance and azimuth between two latitude and longitude points

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.