Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proximity search
Message
From
14/04/2010 06:35:58
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
14/04/2010 00:57:58
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01459851
Message ID:
01460121
Views:
30
>>This is likely related to your latitude, longitude question in SQL server. If so, again I would use MSSQL's spatial data methods. ie:
>>
>>
DECLARE @g geography;
>>SET @g1 = geography::STGeomFromText('POINT(-65.7142 47.7661)', 4326); --Petit-Rocher nord
>>SET @g2 = geography::STGeomFromText('POINT(-65.7305 47.7975)', 4326); --Petit-Rocher sud
>>
>>select @g1.STDistance(@g2);
>>
>>SELECT @g1.STBuffer(3700).STIntersects(@g2); -- true, within 3700 meters
Cetin
>
>Given this:
>
>
>DECLARE @CenterLat Float=47.7795
>DECLARE @CenterLon Float=-65.7191
>DECLARE @SearchDistance Float=250
>
>SELECT Result.Latitude,Result.Longitude
> FROM (SELECT * FROM Test T
> CROSS APPLY (SELECT SIN(@CenterLat/57.2957795130823)*SIN(Latitude/57.2957795130823)+
> COS(@CenterLat/57.2957795130823)*COS(Latitude/57.2957795130823)*
> COS(Longitude/57.2957795130823-@CenterLon/57.2957795130823) AS Temp) Temp
> WHERE (Latitude>=@CenterLat-@SearchDistance/111.0 AND Latitude<=@CenterLat+@SearchDistance/111.0) AND
> (Longitude>=@CenterLon-@SearchDistance/111.0 AND Longitude<=@CenterLon+@SearchDistance/111.0)) Result
> WHERE 3958.75586574*ACOS(CASE WHEN Temp > 1 THEN 1 WHEN Temp < -1 THEN -1 ELSE Temp END)<=@SearchDistance
>
>
>How can we adjust that SQL to benefit of this geography approach?
DECLARE @g geography,
    @area geography ;
SET @g = geography::Point(47.7795,-65.7191,4326) ; --Petit-Rocher
SET @area = @g.STBuffer(250) ;

SELECT  locationId,
        Latitude,
        Longitude,
        @g.STDistance(geoPoint) AS distance
FROM    ( SELECT    locationId,
                    Latitude,
                    Longitude,
                    geography::Point(Latitude,Longitude,4326) AS geoPoint
          FROM      result
        ) geoData
WHERE   @area.STIntersects(geoData.geoPoint) = 1 ;
PS: If you need more speed then consider storing as spatial data and indexing spatial data as explained in SQL 2008 documentation.
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform