SqlGeography STIntersect总是返回false

时间:2014-06-17 17:35:34

标签: c# sql-server geospatial

这个函数我有问题。我试图在Bing Maps AJAX中检测一个点是否在多边形内部。由于Bing映射v7 API没有任何检查功能,我被迫构建自己的代码。从理论上讲,一切都是正确的,但始终是假的。有任何想法吗?我错过了什么?这是我的代码,

using System.Data.SqlTypes;
using Microsoft.SqlServer.Types;

...

[WebMethod]
public static bool PointIntersectPolygon(string PoiLat, string PoiLng, string[] PolyArr)
{
    SqlGeography Point;
    SqlGeography PolyGeo;
    string PolyStr = "", LatStr = "", LngStr = "";

    int Cnt=0;
    while(Cnt < PolyArr.Length) {
        LatStr = PolyArr[Cnt];
        LngStr = PolyArr[Cnt + 1];
        PolyStr = PolyStr + LngStr + " " + LatStr;

        Cnt=Cnt+2;
        if (Cnt < PolyArr.Length) { PolyStr = PolyStr + ", "; }
    }

    //Point = SqlGeography.STPointFromText(new SqlChars("point(" + PoiLng + " " + PoiLat + ")"), 4326);
    //PolyGeo = SqlGeography.STPolyFromText(new SqlChars("polygon((" + PolyStr + "))"), 4326);

    Point = SqlGeography.STPointFromText(new SqlChars("point(-95.2267532349 29.6912727356)"), 4326);
    PolyGeo = SqlGeography.STPolyFromText(new SqlChars("polygon((-95.8686820418 30.0354040414, -95.1099929810 30.1058311462, -95.0110397339 29.5988826752, -95.5437927246 29.5567703247, -95.8686820418 30.0354040414))"), 4326);
    MessageBox.Show(PolyGeo.STContains(Point).ToString());

    bool PolyPoi = (bool)PolyGeo.STContains(Point);
    return PolyPoi;
}

我注释掉了一些行,并将硬编码值检查,我仍然有相同的结果。我很确定多边形内部的这一点。

1 个答案:

答案 0 :(得分:1)

Sql Server地理类型使用左手方法。就像你创建多边形一样,当你包围多边形时左边的任何东西都是多边形的里面

您可以阅读更多内容:SqlGeography: Ring Orientation of Polygons