Hi @mjvincent87
have a look at this script and let me know if it is the direction you are thinking of:
Clear Globals();
Names Default To Here( 1 );
// open data file (dots) - this includes the observation we want to update
dt = Open( "$SAMPLE_DATA/Hurricanes.jmp" );
// introduce the column with the distance to be updated in the dots table
dots << New column ( "Distance", Numeric );
// introduce the column with the distance to be updated in the dots table
Dots << New Column("Bearing", Numeric, "Continuous", Format("Latitude DMS", "PUNSGN", 15, 0));
// extract the longitude and the latitude values from the table - as radians
x = (Column( dots, "Longitude" ) << getValues) * Pi() / 180 ;
y = (Column( dots, "Latitude" ) << getValues) * Pi() / 180 ;
// declare the distance calculation function in KM based on world radius of 6371 KM.
// For statute miles multiply final distance d by 0.621371.
// For nautical miles multiply final distance d by 0.539957
haversine = Function( {long1, lat1, long2, lat2, R = 6371.009},
{Default Local},
a = Sin( (lat1 - lat2) / 2 ) ^ 2 + Cos( lat1 ) * Cos( lat2 ) * Sin( (long1 - long2) / 2 ) ^ 2;
c = 2 * ATan( a ^ 0.5, (1 - a) ^ 0.5 );
d = R * c // *0.621371 For statute miles;
);
wait (0.01);
// run the function along the rows of the table
For( i = 1, i <= N Row( dots ) - 1, i++,
dots:distance[i] = haversine( x[i], y[i], x[i + 1], y[i + 1] )
);
// Declare the Bearing calculation function
Bearing = function ({long1, lat1, long2, lat2 },
{Default Local},
abc = sin (long2 - long1) * cos (lat2);
def = cos (lat1) * sin (lat2) - sin (lat1) *cos (lat2) * cos (long2 - long1) ;
brng = mod (( (atan ( abc, def )) * 180 / pi() ) + 360 , 360) ;
);
wait (0.01);
// run the Bearing function along the rows of the table
For( i = 1, i <= N Row( dots ) - 1, i++,
dots:Bearing[i] = Bearing( x[i], y[i], x[i + 1], y[i + 1] )
);
Best,
ron