纬度超出范围

时间:2017-11-10 15:50:15

标签: sql-server geography sqlgeography

当使用Entity Framework从谷歌地图的边界获取数据时,我得到以下异常:

FormatException:24201:纬度值必须介于-90到90度之间。

POLYGON((81.9882716924738 140.187434563007,21.5587046599696 140.187434563007,21.5587046599696 -40.1641279369925,81.9882716924738 -40.1641279369925,81.9882716924738 140.187434563007))

我可以看到其他人有同样的问题,但还没有找到解决这个问题的方法。我希望点的第一个坐标是纬度,经度是第二个?并且没有一个超过90,那么为什么我会收到此错误?我尝试交换lat和lng,但遇到同样的问题。

这是失败的一行:

var poly = FindByBoundingBox(northEastLat, northEastLng, southWestLat, southWestLng);
DbGeography polygon = DbGeography.FromText(poly, 4326); 

var parksWithinPolygon = dbCtx.SiteList.Where(p => 
    p.PolygonCenter.Intersects(polygon)).Select(p=>p.SiteName).ToList();

正如Damien所述,第一个问题是Sql server首先需要经度然后才能预测经度。这会引发另一个错误,重定向到另一个问题:

“无法完成此操作,因为实例无效”。

我最好的选择是我们建立多边形的方式/顺序。有没有人成功地将谷歌界限映射到SQL服务器中的多边形?总之,我试图在谷歌地图范围内获取任何数据(数据有一个点列)。

下面列出了计算多边形的函数:

public string FindByBoundingBox(double northEastLat, double northEastLng, double southWestLat, double southWestLng)
{   //Create poylgon of bounding box 
    System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
    customCulture.NumberFormat.NumberDecimalSeparator = ".";

    System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
    var bboxWKT = string.Format("POLYGON(({1} {0},{1} {2},{3} {2},{3} {0},{1} {0}))", northEastLat, northEastLng, southWestLat, southWestLng);

    return bboxWKT;
}

1 个答案:

答案 0 :(得分:0)

好的,我明白了。正如Damien所说,坐标的顺序是google的oppesite。在SQL中,长期需要先行。接下来是什么是“左手规则”。您需要从左下角开始创建多边形,然后逆时针方向创建。

相关问题