Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proximity search
Message
From
14/04/2010 07:09:45
 
 
To
14/04/2010 06:59:36
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
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:
01460126
Views:
24
>>Michel,
>>
>>A start
>>
>>There's a problem with the SearchDistance mapping range for 5,000 km brussels, ie LongMin and LongMax - I do not know why. If I apply min/max and a range of 5,000 km it does not work (tried even 7000)
>>
>>For small distance tests - no problem
>>
>>
>>declare @City table
>>(	ci_Id	int,
>>	ci_desc	varchar(60),
>>	ci_pos geography 
>>	)
>>
>>insert into @City (ci_Id, ci_desc, ci_pos)
>>select 1, 'Here', geography::Point(47.77950, -65.7191, 4326)
>>union all
>>select 2, 'There', geography::Point(47.5993, -65.6506, 4326)
>>union all
>>select 3, 'Brussels', geography::Point(50.00 + 50./60. + 0/3600., 4.0 + 20./60. + 0/3600, 4326)
>>
>>
>>select * from @City
>>
>>declare @CenterLat float=47.7795
>>declare @CenterLon float=-65.7191
>>declare @SearchDistance float=5000
>>
>>-- http://en.wikipedia.org/wiki/Latitude_and_longitude
>>declare @LatitudinalDegreeKm  float = 110.9
>>declare @LongitudinalDegreeKm  float = 111.3
>>
>>declare @LatMin float = @CenterLat - @SearchDistance/@LatitudinalDegreeKm
>>declare @LatMax float = @CenterLat + @SearchDistance/@LatitudinalDegreeKm
>>
>>declare @LongMin float = @CenterLon - @SearchDistance/@LongitudinalDegreeKm
>>declare @LongMax float = @CenterLon + @SearchDistance/@LongitudinalDegreeKm
>>
>>declare @Here geography = geography::Point(@CenterLat, @CenterLon, 4326)
>>
>>
>>
>>/*
>>select *, 
>>		ci_pos.Lat as Latitude,
>>		ci_pos.Long	as Longitude,
>>		@Here.STDistance(ci_pos)/1000.0 as distanceKm
>>		from @City
>>*/
>>select *, 
>>		@Here.STDistance(ci_pos)/1000.0 as distanceKm,
>>		ci_pos.Lat as Latitude, 
>>		ci_pos.Long as Longitude,
>>		@LatMin as lat_min,
>>		@LatMax as lat_max,
>>		@LongMin as long_min, 
>>		@LongMax as long_max
>>		from @City 
>>
>>select *, 
>>		@Here.STDistance(ci_pos)/1000.0 as distanceKm,
>>		ci_pos.Lat as Latitude, 
>>		ci_pos.Long as Longitude,
>>		@LatMin as lat_min,
>>		@LatMax as lat_max,
>>		@LongMin as long_min, 
>>		@LongMax as long_max
>>		from @City 
>>	where	(	ci_pos.Lat between @LatMin and @LatMax )
>>		and	(	ci_pos.Long between @LongMin and @LongMax) 
>>		and	( @Here.STDistance(ci_pos)/1000.0 <= @SearchDistance )
>>	
>>
>>	
>>
>
>Spatial methods work but an area within a fixed distance from a point is not a rectangular area. Instead try STBuffer(). ie:
>
DECLARE @area geography;
>SET @area = @Here.STBuffer( @SearchDistance * 1000 );
>
>select *, 
>		@Here.STDistance(ci_pos)/1000.0 as distanceKm,
>		ci_pos.Lat as Latitude, 
>		ci_pos.Long as Longitude
>		from @City 
>	where	@area.STIntersects( ci_pos ) = 1;
>
>Cetin

I'm just discovering the Geography and spacial types and had quite some fun yesterday - have never needed to delve in there. But I'll consider and read up more on the types in SqlServer. Interesting stuff

The reason the rectangle was originally added was to roughly limit the candidates based on their Lat/Long and then filter those out where the distance was greater
I thought that this made sense performancewise since (1) the Lat/Long was stored in the table and (2) the distance calculation with all the trigonometric functions must use quite some cpu cycles
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform