SQL Server 2008 Spatial - How to create a circle? - SimonS Blog on SQL Server Stuff

SQL Server 2008 Spatial - How to create a circle?

How do you create a circle in a planar system. Ok so there are some funky algorithms for creating a set of points all the way round the circle.

Well there is a much easier way.

Create a point i.e. POINT (10 10) and the use the STBuffer(radius) method to get a circle whose centre is at the point and with the radius specified, i.e.

DECLARE @g geometry;

SET @g = geometry::STGeomFromText('POINT(5 5)', 0);

SELECT @g.STBuffer(1).ToString();

Creates a polygon with 129 points aaaaaagggghhhhhh. You can reduce the number of points by using the Reduce method. Reduce with a value of 0.05 results in a 17 point polygon which is a fairly accurate circle

You can achieve this in one step using the BufferWithTolerance method. To get a 17 point polygon you specify a tolerance of 0.1.

POLYGON ((5 4, 5.38924515247345 4.0785849690437317, 5.70710676908493 4.29289323091507, 5.9214150309562683 4.61075484752655, 6 5, 5.9214150309562683 5.38924515247345, 5.70710676908493 5.70710676908493, 5.38924515247345 5.9214150309562683, 5 6, 4.61075484752655 5.9214150309562683, 4.29289323091507 5.70710676908493, 4.0785849690437317 5.38924515247345, 4 5, 4.0785849690437317 4.61075484752655, 4.29289323091507 4.29289323091507, 4.61075484752655 4.0785849690437317, 5 4))

If you want to see what this looks like try the SpatialViewer on codeplex http://www.codeplex.com/SpatialViewer


 



-
Published 09 January 2008 23:21 by simonsabin

Comments

No Comments