Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Equivalent of atn function
Message
De
13/04/2010 18:02:37
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
13/04/2010 12:49:11
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01459871
Message ID:
01460081
Vues:
31
>>I think you can replace 4*((4*atn(1/5))-(atn(1/239))) by PI()
>>
>>And if you store the Latitude and Longitude in radians, then it becomes
>>
>>SET XAxis = cos([TABLENAME].Latitude) * cos([TABLENAME].Longitude)
>>
>>
>>likewise
>>SET YAxis = cos([TABLENAME].Latitude) * sin([TABLENAME].Longitude)
>>SET ZAxis = sin([TABLENAME].Latitude)
>>
>>
>
>Thanks
>
>I just want to verify that part. My code to replace those values are as follow:
>
>
>UPDATE test SET XAxis = (cos(((PI())/180)*Latitude)*cos(((PI())/180)*Longitude))
>UPDATE test SET XAxis = (cos(((PI())/180)*Latitude)*sin(((PI())/180)*Longitude))
>UPDATE test SET ZAxis = (sin(((PI())/180)*Latitude))
>
>
>Then, applying the related code would give the image attached:
>
>
>declare @CenterLat float=47.7795
>declare @CenterLon float=-65.7191
>declare @EarthRadius float=6371 
>declare @SearchDistance float=10000
>
>declare @CntXAxis float
>declare @CntYAxis float
>declare @CntZAxis float
>
>set @CntXAxis = cos(radians(@CenterLat)) * cos(radians(@CenterLon))
>set @CntYAxis = cos(radians(@CenterLat)) * sin(radians(@CenterLon))
>set @CntZAxis = sin(radians(@CenterLat))
>
>select *,  ProxDistance = @EarthRadius * acos( XAxis*@CntXAxis + YAxis*@CntYAxis + ZAxis*@CntZAxis)
>from test
>where  @EarthRadius * acos( XAxis*@CntXAxis + YAxis*@CntYAxis + ZAxis*@CntZAxis) <= @SearchDistance
>order by ProxDistance ASC
>
>
>The code works, but the distance calculated is enormous. There is only about 12 to 16 km between those two coordinates.


You are using SQL 2008 and your values sound to be UTM values. Then why don't you simply utilize SQL 2008's spatial datatype and its methods. For example your location is somewhere near Petit-Rocher. Using Petit-rocher nord and sud coordinates:
DECLARE @g1 geography, @g2 geography;

SET @g1 = geography::STGeomFromText('POINT(-65.7142 47.7661)', 4326);
SET @g2 = geography::STGeomFromText('POINT(-65.7305 47.7975)', 4326);

select @g1.STDistance(@g2);
I get result as 3698.76 meters which looked right to me.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform