加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

将SQL地理转换为C#

发布时间:2020-12-12 16:51:08 所属栏目:MsSql教程 来源:网络整理
导读:这个地理空间T-SQL代码的C#相当于什么? 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(
这个地理空间T-SQL代码的C#相当于什么?
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#代码.

解决方法

尝试这个:
public bool OneOffSTIntersect()
{
    var g =
        Microsoft.SqlServer.Types.SqlGeography.STGeomFromText(
            new System.Data.SqlTypes.SqlChars(
                "POLYGON((-122.358 47.653,-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 Methods页面链接到T-SQL中关键调用的每个C#等效信息的信息 – 例如. STIntersects.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读