Locations in this area: SQL Server geography datatype

Working with maps and database, SQL Server 2008 may help you with this new data type: geography .
This datatype takes part in spatial data features introduces in SQL Server 2008.

When you want to select location, in 50KM from xyz (a place well known), the simplest question is: is distance from center less than 50 km ?
Here is a very simple example about it šŸ˜‰


DECLARE @area geography;
 SET @area = geography::STGeomFromText('POINT(' +
 CAST(@LatitudeArea as nvarchar(50)) +  ' ' +
 CAST(@LongitudeArea as nvarchar(50))  + ')', 4326) ;

 DECLARE @distance int;
 SELECT @distance =
 (geography::STGeomFromText('POINT(' +
 CAST(@LatitudePoint as nvarchar(50)) + ' ' +
 CAST(@LongitudePoint as nvarchar(50)) +')', 4326)).STDistance(@area);


 IF (@distance < @RadiusArea *1000)
 RETURN 1

 RETURN 0

Technorati Tags: , , .
Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: