将SQL地理学C# [英] Convert SQL geography to C#
本文介绍了将SQL地理学C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是C#相当于这个地理空间T-SQL代码
What is the C# equivalent of this geospatial T-SQL code?
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#代码
I am trying to find a point in a polygon using the SqlGeometry
data type -- and can with the above T-SQL; but I do not understand how to achieve equivalent C# code.
推荐答案
试试这个:
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
。
MSDN's SqlGeography Methods page links to info on each of the C# equivalents to the critical calls in your T-SQL - e.g. STIntersects
.
这篇关于将SQL地理学C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文