转换SQL地理学C#(Convert SQL geography to C#)

2019-09-02 08:11发布

什么是C#相当于这个地理空间T-SQL代码?

DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326);
SET @h = geography::Point(47.653, -122.358, 4326)

SELECT @g.STIntersects(@h)

我试图用找到一个多边形点SqlGeometry数据类型-并能与上述T-SQL; 但我不明白如何实现等价的C#代码。

Answer 1:

试试这个:

public bool OneOffSTIntersect()
{
    var g =
        Microsoft.SqlServer.Types.SqlGeography.STGeomFromText(
            new System.Data.SqlTypes.SqlChars(
                "POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))"), 4326);
    // suffix "d" on literals below optional but explicit
    var h = Microsoft.SqlServer.Types.SqlGeography.Point(47.653d, -122.358d, 4326);

    // rough equivalent to SELECT
    System.Console.WriteLine(g.STIntersects(h));

    // Alternatively return from a C# method or property (get).
    return g.STIntersects(h);
}

MSDN的SqlGeography方法页面链接到每一个C#等同于你的T-SQL的关键呼叫信息-例如STIntersects



文章来源: Convert SQL geography to C#