sandip
sandip

Reputation: 185

find list of polygons from radius in sql server

I have stored list of polygons as Geometry object in Sql Server and then based on Lat/Long I am drawing radius around that point.

Here is the statement I used to draw the radius.

DECLARE @radiusInMeters FLOAT = 1000; 

DECLARE @radius GEOMETRY = GEOMETRY::Point(59.9283128,10.7132419, 4326).STBuffer(@radiusInMeters); 

Once I get the radius I am searching for polygons falls withing that Radius using following statement.

SELECT * FROM MyTableName WHERE area.STWithin(@radius) = 1;

But instead of the polygons fall within the radius, I am getting all the records from my table.

Upvotes: 2

Views: 410

Answers (1)

sandip
sandip

Reputation: 185

I found the solution. Thanks Barry King for such great post.

https://sqldev.wordpress.com/2010/06/24/sql-server-spatial-geometry-radius/

Updated:

Here is the statement solved my problem.

DECLARE @radius INT = 1000 -- e.g. in metres
DECLARE @geo geometry = geometry::Point(10.7132419,59.9283128, 4326).MakeValid()
SET @geo = GEOMETRY::STGeomFromWKB(GEOGRAPHY::STGeomFromWKB(@geo.STAsBinary(),4326).STBuffer(@radius).STAsBinary(),4326)
Select @geo.STAsText() 

Upvotes: 1

Related Questions