【问题标题】:DbGeography.Distance() returning incorrect distanceDbGeography.Distance() 返回不正确的距离
【发布时间】:2013-04-15 19:41:59
【问题描述】:

我正在试验 System.Data.Spatial.DbGeography,我想用它来确定从一个坐标到另一个坐标的距离(将存储在 SQL 服务器中)。

我的坐标是纬度/经度,我是从 Bing 地图获取的(我也尝试过使用谷歌地图的坐标,结果相同)。

var osloCentralStation = DbGeography.FromText("POINT(59.9109 10.7523)", 4326);
var drammen = DbGeography.FromText("POINT(59.7378 10.2050)", 4326);
Console.WriteLine("Distance: {0}km", osloCentralStation.Distance(drammen) / 1000);

返回: 距离:63,4340839088124km

返回的距离大约是应有的两倍。

https://maps.google.com/maps?saddr=59.9109+10.7523&daddr=59.7378+10.2050

有人知道发生了什么吗?

【问题讨论】:

    标签: google-maps coordinates gis bing-maps geospatial


    【解决方案1】:

    您没有以正确的顺序在 WKT 中声明元素。 WKT 应该是你的情况:

    POINT(10.2050 59.7378)
    

    在此处查看 OGC 标准:

    然后它必须声明为:

    POINT(LONGITUDE LATITUDE)
    

    另外请记住,这不是行车距离,而是空中距离。

    【讨论】:

    • 这是我所追求的空中距离。我将使用距离从坐标获取给定半径内的兴趣点。
    【解决方案2】:

    事实证明,在创建新的 DbGeography 对象时,lat/long 被指定为 long/lat。

    我已经写了一个小辅助方法,这样我以后就不会再出错了:

    private static DbGeography CreateDbGeography(double latitude, double longitude, int srid = 0)
    {
        var text = string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", longitude, latitude);
    
        if (srid > 0)
        {
            return DbGeography.FromText(text, srid);
        }
    
        return DbGeography.FromText(text);
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      • 2013-01-15
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多