Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Tue, 31 May 2005 @ 17:28:32 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Distance based on latitude and longitude
 
From:   Brian.Jones

Thank you for the incredible information. The summary below is what I will be using. Please review and comment if you can.

Thank you again. Your insight is greatly appreciated. -Brian

Summary:

1. use Haversine Formula for the greatest accuracy

2. use radians instead of degrees

3. convert degrees to radians by multiplying by PI and dividing by 180

4. use 7,912 miles as the Earth's diameter

5. use (22/7) for PI

6. format distance in miles to 8 decimal places.

7. SQL code of an example:

          SELECT
              35.25927 AS LAT1
             ,-81.2238 AS LON1
             ,35.22143 AS LAT2
             ,-81.1492 AS LON2
             ,CAST(
                   (7912*
                   ATAN (
                         SQRT (
                               (SIN((LAT2*(22/7)/180-LAT1*(22/7)/180)/2)**2)
                               +(COS(LAT1*(22/7)/180)*COS(LAT2*(22/7)/180)*(SIN((LON2*(22/7)/180-LON1*(22/7)/180)/2)**2))
                              )
                         /SQRT (
                                1-(SIN((LAT2*(22/7)/180-LAT1*(22/7)/180)/2)**2)
                                +(COS(LAT1*(22/7)/180)*COS(LAT2*(22/7)/180)*(SIN((LON2*(22/7)/180-LON1*(22/7)/180)/2)**2)
                               )
                        )
                   )
                  ) AS DECIMAL(12,8)) AS MILES


     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023