DbGeography相交方法不起作用

360*_*ode 4 c# sql-server spatial

System.Data.Spatial.DbGeography.Intersects方法似乎总是对我返回true.我不确定为什么会这样.我在下面创建了一个简单的命令行代码段,导致下面的控制台输出

Intersects
Intersects
Run Code Online (Sandbox Code Playgroud)

这一点显然没有接近界限,因此不应该相交.

DbGeography bounds = DbGeography.PolygonFromText("POLYGON ((146 -20,148 -20,148 -22,146 -22,146 -20))", 4326);
DbGeography point = DbGeography.PointFromText("POINT (0 0)", 4326);
if (point.Intersects(bounds) == true)
    Console.WriteLine("Intersects");
else
    Console.WriteLine("Does NOT intersect");

if (bounds.Intersects(point) == true)
    Console.WriteLine("Intersects");
else
    Console.WriteLine("Does NOT intersect");
Run Code Online (Sandbox Code Playgroud)

Ben*_*hul 5

这一点显然没有接近界限,因此不应该相交.

有一条规则:只要你说"清楚",就要准备好做错.:)

开玩笑,你有一个环定向问题.也就是说,指定点的顺序很重要.当您指定角落时,您已经定义了一个整个地球的区域,其中有一个非常小的洞.请尝试使用此代码:

POLYGON ((146 -20,146 -22,148 -22,148 -20,146 -20))
Run Code Online (Sandbox Code Playgroud)

那么,你怎么知道你有一个方向问题?我喜欢使用的一种启发式方法是,如果对象的包络角度很大(90度=一个半球),那么您已经错误地指定了排序.EnvelopeAngle在数据库引擎中的Geography数据类型上有一个方法(但它看起来不像在C#中的DbGeography类中)来确定这一点.还有一种方便的方法(再次肯定在数据库中而不是在C#中)重新调整所调用的环,这并不奇怪ReorientObject.