Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 01 Jun 2005 @ 14:23:29 GMT


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


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

Below is the updated SELECT using 3.14159265 for PI. Thank you. -Brian

     /***************
     CALCULATE DISTANCE BETWEEN 2 LOCATIONS BASED ON LAT AND LON
     FIRST QUERY IS BASED ON LAT AND LON UNITS
     OF DEGREES AND WE NEED TO CONVERT TO RADIANS

     SECOND QUERY IS BASED ON LAT AND LON UNITS OF RADIANS
     ***************/
     -- DEGREES
     SELECT
        35.25927 AS LAT1
        ,-81.2238 AS LON1
        ,35.22143 AS LAT2
        ,-81.1492 AS LON2
        ,CAST(
              (7912*
               ATAN (
                     SQRT (
                           (SIN((LAT2*(3.14159265)/180-LAT1*(3.14159265)/180)/2)**2)
                           +(COS(LAT1*(3.14159265)/180)*COS(LAT2*(3.14159265)/180)
                           *(SIN((LON2*(3.14159265)/180-LON1*(3.14159265)/180)/2)**2))
                          )
                     /SQRT (
                            1-(SIN((LAT2*(3.14159265)/180-LAT1*(3.14159265)/180)/2)**2)
                            +(COS(LAT1*(3.14159265)/180)*COS(LAT2*(3.14159265)/180)
                            *(SIN((LON2*(3.14159265)/180-LON1*(3.14159265)/180)/2)**2)
                           )
                    )
              )
             ) AS DECIMAL(12,8)) AS MILES;

     -- RADIANS
     SELECT
        35.25927*(3.14159265)/180 AS LAT1
        ,-81.2238*(3.14159265)/180 AS LON1
        ,35.22143*(3.14159265)/180 AS LAT2
        ,-81.1492*(3.14159265)/180 AS LON2
        ,CAST(
              (7912*
               ATAN (
                      SQRT (
                            (SIN((LAT2-LAT1)/2)**2)
                            +(COS(LAT1)*COS(LAT2)
                            *(SIN((LON2-LON1)/2)**2))
                           )
                      /SQRT (
                             1-(SIN((LAT2-LAT1)/2)**2)
                             +(COS(LAT1)*COS(LAT2)
                             *(SIN((LON2-LON1)/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