A friend of mine wrote this script for some reason and forwarded to me for the heck of it! I have no use for it but figured somebody else might be looking for it! So here it is... If you have any questions, feel free to post 'em and I will run it by Narayan.
-- =============================================
-- ==============================
-- Author:
-- Create date: <24/04/2009>
-- Description:
-- =============================================
CREATE FUNCTION [dbo].[udfLatLonRadiusDistance]
(
@lat1Degrees decimal(15,12),
@lon1Degrees decimal(15,12),
@lat2Degrees decimal(15,12),
@lon2Degrees decimal(15,12)
)
RETURNS decimal(9,2)
AS
BEGIN
DECLARE @earthSphereRadiusNauticalMiles as decimal(10,6)
DECLARE @nauticalMileConversionToMilesFactor as decimal(7,6)
SELECT @earthSphereRadiusNauticalMiles = 6366.707019
SELECT @nauticalMileConversionToMilesFactor = .621371
-- convert degrees to radians
DECLARE @lat1Radians decimal(15,12)
DECLARE @lon1Radians decimal(15,12)
DECLARE @lat2Radians decimal(15,12)
DECLARE @lon2Radians decimal(15,12)
SELECT @lat1Radians = (@lat1Degrees / 180) * PI()
SELECT @lon1Radians = (@lon1Degrees / 180) * PI()
SELECT @lat2Radians = (@lat2Degrees / 180) * PI()
SELECT @lon2Radians = (@lon2Degrees / 180) * PI()
-- formula for distance from [lat1,lon1] to [lat2,lon2]
RETURN ROUND(2 * ASIN(SQRT(POWER(SIN((@lat1Radians - @lat2Radians) / 2) ,2)
+ COS(@lat1Radians) * COS(@lat2Radians) * POWER(SIN((@lon1Radians - @lon2Radians) / 2), 2)))
* (@earthSphereRadiusNauticalMiles * @nauticalMileConversionToMilesFactor), 4)
END
Please consider the environment before printing this blog! Go Green!
Credit for this idea goes to http://blogs.msdn.com/chrishays/archive/2004/08/30/GreenBarMatrix.aspx
Comments
MicroStrategy Online Training USA
MicroStrategy Online Training India