9

每当我使用 FreeMapTools 计算我和朋友邮政编码之间的距离时,它都会给我以下信息:

  • 300.788 英里
  • 484.072 公里

FreeMapTools 的屏幕截图显示 300.788 英里 FreeMapTools 的屏幕截图显示 484.072 公里

当我使用 NetTopologySuite 时,我得到了5.2174236612815返回的值。

  • 5.2174236612815乘以 60 是313.04541967689
  • 5.2174236612815乘以 100 是521.74236612815

这些值与 FreeMapTools 上显示的距离并不太远,但仍然相距甚远。

我的代码如下:

using System;
using GeoAPI.Geometries;
using NetTopologySuite;

namespace TestingDistances
{
    class Program
    {
        static void Main(string[] args)
        {
            var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);

            // BT2 8HB
            var myPostcode = geometryFactory.CreatePoint(new Coordinate(-5.926223, 54.592395));

            // DT11 0DB
            var myMatesPostcode = geometryFactory.CreatePoint(new Coordinate(-2.314507, 50.827157));

            var distance = myPostcode.Distance(myMatesPostcode);
            Console.WriteLine(distance); // returns 5.2174236612815

            Console.WriteLine(distance * 60); //similar to miles (313.04541967689)
            Console.WriteLine(distance * 100); //similar to km (521.74236612815)

            Console.ReadLine();
        }
    }
}

如何将 NetTopologySuite 返回的值准确转换为英里/距离?这是我不知道的某种形式的 GPS 距离单位吗?

谢谢

4

2 回答 2

4

正如 DavidG 正确提到的,NetTopologySuite 假定笛卡尔坐标。您的坐标是地理坐标(纬度/经度)。因此,您得到的结果是无用的,不能转换为米或英里。

您必须在调用距离方法之前执行坐标变换,例如使用 ProjNet:

var csWgs84 = ProjNet.CoordinateSystems.GeographicCoordinateSystems.WGS84;
const string epsg27700 = "..."; // see http://epsg.io/27700
var cs27700 = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(epsg27700);
var ctFactory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
var ct = ctFactory.CreateFromCoordinateSystems(csWgs84, cs27700);
var mt = ct.MathTransform;

var gf = new NetTopologySuite.Geometries.GeometryFactory(27700);

// BT2 8HB
var myPostcode = gf.CreatePoint(mt.Transform(new Coordinate(-5.926223, 54.592395)));
// DT11 0DB
var myMatesPostcode = gf.CreatePoint(mt.Transform(new Coordinate(-2.314507, 50.827157)));

double distance = myPostcode.Distance(myMatesPostcode);
于 2019-03-06T12:43:12.837 回答
2

The number appears to just be a simple Cartesian coordinate system. For example:

var point1 = geometryFactory.CreatePoint(new Coordinate(0, 0));
var point2 = geometryFactory.CreatePoint(new Coordinate(0, 270));

var distance = point1.Distance(point2);

Here distance is 270. If we use 0, 0 and 30, 40 the distance is 50. That's just a simple Pythagoras calculation (i.e. 30^2 + 40^2 = 50^2)

于 2019-03-04T22:29:42.940 回答