gcd_slc
The gcd_slc function calculates the great circle distance using the spherical law of cosines.
Synopsis
gcd_slc(radius,lat1,lon1,lat2,lon2)
Latitude and longitude are given in radians.
Summary
Great-circle distance calculated with spherical law of cosines.
Example
This example uses the spherical law of cosines to find the great circle distance between two points assuming a mean earth radius of 6371 kilometers. The example is published in Wikipedia.Â
The latitude and longitude for Los Angeles International Airport (LAX) is N 33.94°, W 118.4°. In radians, these values are .5924 and -2.0665. The latitude and longitude for Nashville International Airport (BNA) in Nashville, Tennessee is N 36.12°, W 86.67°. In radians, these values are .6304 and -1.5127. Create an input array to contain these values:
AFL% store(build(<airport:string, lat:double, lon:double>[i=0:1], '[(\'LAX\', .5924, -2.0665), (\'BNA\', 0.6304, -1.5127)]', true), airports);
The output is:
{i} airport,lat,lon {0} 'LAX',0.5924,-2.0665 {1} 'BNA',0.6304,-1.5127
The input attribute arguments for the gcd_slc function must be from the same cell. From the airports array, use filter and cross_join to build a trip array describing the airport entries we care about. The cast operator is used to rename the lat and lon attributes:
AFL% store(cast(cross_join(filter(airports, airport='LAX'), filter(airports, airport='BNA')), <from:string, latf:double, lonf:double, to:string, latt:double, lont:double>[i;j]), trip);
The output is:
{i,j} from,latf,lonf,to,latt,lont {0,1} 'LAX',0.5924,-2.0665,'BNA',0.6304,-1.5127
Use apply and gcd_slc to add the spherical law of cosines great circle distance attribute:
AFL% apply(trip, distance, gcd_slc(6371.0, latf, lonf, latt, lont));
The output is:
{i,j} from,latf,lonf,to,latt,lont,distance {0,1} 'LAX',0.5924,-2.0665,'BNA',0.6304,-1.5127,2886.43
Remove the example arrays:
AFL% remove(airports); remove(trip);
Â