Compass_Direction

Posted by Philip Leitch Monday, March 8, 2010 10:30:24 PM Categories: Geometry Geospatial Scalar Function
CREATE Function [dbo].[Compass_Direction] (@Bearing as float)
/*
www.prlsoftware.com
Author: Philip Leitch
Date: 2010
Purpose: This function converts a Bearing into human readable compass text.
Copyright: Philip Leitch 2010
Licensing: This code may be used or modified but if the code is included in a software package attribution to me must be made.
Liability: The developer assumes all liability when using this code.
Notes:
*/
returns Varchar(5) as
Begin
declare @North_Distance float
set @north_distance = dbo.North_Distance(@Bearing)
declare @East_Distance float
set @East_Distance = dbo.East_Distance(@Bearing)
return case when @East_Distance between 11.25 and 33.75 then 'E' when @East_Distance between  146.25  and 168.75 then 'W' else '' end  +
 case when @North_Distance <= 56.26  then 'N' when @North_Distance >= 123.74  then 'S' else '' end +
 case when @North_Distance between 11.25 and 33.75 then 'N' when @North_Distance between  146.25  and 168.75 then 'S' else '' end  +
 case when @East_Distance between 45+11.25 and 45+33.75 then 'E' when @East_Distance between  146.25-45  and 168.75-45 then 'W' else '' end  +
 case when @North_Distance between 45+11.25 and 45+33.75 then 'N' when @North_Distance between  146.25-45  and 168.75-45 then 'S' else '' end  +

 case when @East_Distance <= 56.26  then 'E' when @East_Distance >= 123.74  then 'W' else '' end
end
Copyright 2009 Philip Leitch

Comments

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?