Disperse Point

487
0
10-19-2016 10:42 AM
Farhan_Tariq
New Contributor

i have many point in same coordinate and display in web application on different location by dispersing .

i am searching one function to solve the problem and i achieve in postgresgis but not achieve in sql server. kindly define my function that is mention below

USE [abc]
GO
/****** Object: UserDefinedFunction [dbo].[fun_ReturnFinalDestination] Script Date: 10/19/2016 22:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[fun_ReturnFinalDestination]
( @latY1 float, -- example 50.80576
@longX1 float, -- example -1.111801667
@dist decimal(18,9), -- supplied in metres example 170
@bearing decimal(18,9) -- supplied in degrees example 180
)
RETURNS @LatYLongX TABLE
(
LatY float NULL,
LongX float NULL
)
AS
BEGIN
-- Fill the table variable with the rows for your result set
declare @latY2 float
declare @longX2 float
declare @radiusEarth decimal(18,9) = 6378137.0
set @latY1 = RADIANS(@latY1) -- convert lat to radian
set @longX1 = RADIANS(@longX1) -- convert long to radian
set @bearing = RADIANS(@bearing) -- convert degrees to radian
set @laty2 = Asin(Sin(@laty1) * Cos(@dist / @radiusEarth ) + Cos(@laty1) * Sin(@dist / @radiusEarth ) * Cos(@bearing ))
set @longx2 = @longx1 + Atn2(Sin(@bearing) * Sin(@dist / @radiusEarth ) * Cos(@laty1), Cos(@dist / @radiusEarth ) - Sin(@laty1) * Sin(@laty2))

set @laty2 = DEGREES(@laty2) -- convert back to degrees
set @longx2 = DEGREES(@longx2) -- convert back to degrees

INSERT @LatYLongX
SELECT @laty2, @longx2
RETURN
END

0 Kudos
0 Replies