views:

34

answers:

2

I have geographic data that was loaded into the geography datatype. For very specific purposes, I now need to have store this as a geometry. However, I need to perform a query like this.

DECLARE @radius INT -- e.g. 3000 metres

DECLARE @geo geometry -- my starting shape

SET @geo = @geo.STBuffer(@radius) -- this obviously doesnt work.. 

SELECT Geo FROM GeometryTable 
WHERE Geo.STWithin (@geo) = 1
A: 

Meters are a measure of length while radians are a measure of an angle so i don't think you can.

Are you trying to calculate an arc length?

Take a look at the links below:

Abe Miessler
A: 

This trick might work, if someone can validate this technique or provide a better alternative then they'll get the accepted answer.

Basically, I am thinking I can use the STBuffer of a geography which will apply the correct radius in metres around my geographical shape and then I convert back to a geometry. As the shapes were loaded originally as geography all the points are the same. This shape-flip should give me a resulting geometry with a pretty accurate buffer around it.

DECLARE @radius INT -- e.g. 3000 metres

DECLARE @geo geometry -- my starting shape

SET @geo = GEOMETRY::STGeomFromWKB(GEOGRAPHY::STGeomFromWKB(@geo.STAsBinary(),
           4326).STBuffer(@radius).STAsBinary(),4326)

SELECT Geo FROM GeometryTable 
WHERE Geo.STWithin (@geo) = 1
Barry King