I wish to create a spatial object representing an ellipse in SQL Server 2008 R2.
I have the point coordinates, and min and major axis values.
The closest built in function I can find, which doesn't get me all the way there, is STBuffer - which creates a buffered radius around the point e.g:
DECLARE @g geography;
SET @g = geography::STGeomFromText('POINT(-122.360 47.656)', 4326);
SELECT @g.STBuffer(5);
Am I missing something? This seems quite basic.
I really don't want to create a set of polygon coordinates to represent this shape - it just seems overkill.
Thanks in advance.
This wasn't possible. I solved the problem by creating a WKT Polygon string representation in C#.
The equation in summary is below:
var step = 2*Math.PI/40; // creates 40 points (1 for each "step")
var radians = 5.868;
var semiMajMetres = 400;
var semiMinMetres = 200;
var latMetres = latVal*110575; // converts degree value to metres value
var lonMetres = lonVal*111303; // assumes you have variables with these known values
for(double theta = 0; theta <= 2 * Math.PI; theta += step)
{
var lon = lonMetres + semiMajMetres * Math.Cos(theta) * Math.Cos(radians) - semiMinMetres * Math.Sin(theta) * Math.Sin(radians);
var lat = latMetres + semiMajMetres * Math.Cos(theta) * Math.Sin(radians) + semiMinMetres * Math.Sin(theta) * Math.Cos(radians);
lat /= 110575; // convert metres back to degrees
lon /= 111303;
// Create your POLYGON string with these values in format POLYGON((lon lat, lon lat, lon lat, lon lat))
// Note that the last coordinate set MUST be identical to the first coordinate set - confirm this and rectify the last coordinate double precision, if required
}
Now create the geography object:
DECLARE @g geography;
SET @g = geography::STPolyFromText('POLYGON(([lonValue] [latValue], POINT([lonValue] [latValue], POINT([lonValue] [latValue], POINT([lonValue] [latValue]))', 4326);
SELECT @g;