Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 27 May 2005 @ 13:54:52 GMT


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


Subj:   Re: Distance based on latitude and longitude
 
From:   Geoffrey Rommel

  I would like to calculate the distance between 2 physical locations based on their latitude and longitude. Has anyone done this in Teradata?  


Yep.

     select (sin((lat2 - lat1)/2.0)**2) + (cos(lat1) * cos(lat2) * sin((long2 - long1)/2.0)**2) as A,

             7917.53141 * atan2( sqrt(1.0-a), sqrt(a) ) as dist from wherever....;

7917.53141 = the mean volumetric radius of the earth from NASA, converted to miles and multiplied by 2.

There are some gotchas here: (1) all latitudes and longitudes must be in radians; (2) be sure to divide by 2.0, not 2, because you don't want it to truncate; (3) the arguments to atan2 in Teradata are the reverse of what they are in C (why, Lord, why?).



     
  <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