将SQL地理转换为C#
这个地理空间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.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 Methods页面链接到T-SQL中关键调用的每个C#等价物的信息 – 例如STIntersects
。
上述就是C#学习教程:将SQL地理转换为C#分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1034442.html