创建椭圆地理表示

时间:2015-02-25 13:29:54

标签: sql tsql sql-server-2008-r2 spatial sqlgeography

我希望在SQL Server 2008 R2中创建一个表示椭圆的空间对象。

我有点坐标,min和长轴值。

我能找到的最接近的内置函数是STBuffer,它不会让我一直到达那里,它创造了一个缓冲的半径,例如:

DECLARE @g geography;
SET @g = geography::STGeomFromText('POINT(-122.360 47.656)', 4326);
SELECT @g.STBuffer(5);

我错过了什么吗?这似乎很基本。

我真的不想创建一组多边形坐标来表示这种形状 - 这看起来有些过分。

提前致谢。

1 个答案:

答案 0 :(得分:1)

这是不可能的。我通过在C#中创建WKT Polygon字符串表示来解决问题。

总结如下:

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
}

现在创建地理对象:

DECLARE @g geography;
SET @g = geography::STPolyFromText('POLYGON(([lonValue] [latValue], POINT([lonValue] [latValue], POINT([lonValue] [latValue], POINT([lonValue] [latValue]))', 4326);
SELECT @g;