【问题标题】:Create Ellipse Geography Representation创建椭圆地理表示
【发布时间】:2015-02-25 13:29:53
【问题描述】:

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

我有点坐标,以及最小和长轴值。

我能找到的最接近的内置函数是 STBuffer,它在该点周围创建一个缓冲半径,例如:

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

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

我真的不想创建一组多边形坐标来表示这个形状——这似乎有点矫枉过正。

提前致谢。

【问题讨论】:

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


    【解决方案1】:

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

    等式总结如下:

    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;
    

    【讨论】:

    • 神奇的数字 110575 和 111303 从何而来?另外,是否有必要进行乘法运算?
    • 经纬度转换需要110575和111303-更多请看下面-Click Here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多