NetTopologySuite return 距离采用哪种单位,如何将其转换为 miles/km?

What sort of unit does NetTopologySuite return distances in, and how can I convert it to miles/km?

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

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

这些值与 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 返回的值准确地转换为 miles/distances?这是我不知道的某种形式的 GPS 距离单位吗?

谢谢

该数字似乎只是一个简单的笛卡尔坐标系。例如:

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

var distance = point1.Distance(point2);

这里distance是270。如果我们使用0, 030, 40,距离是50。这只是一个简单的毕达哥拉斯计算(即30^2 + 40^2 = 50^2

正如 DavidG 正确提到的那样,NetTopologySuite 假定笛卡尔坐标。您的坐标是地理坐标 (lat/lon)。因此,您得到的结果是无用的,无法转换为米或英里。

在调用距离方法之前必须进行坐标转换,例如使用 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);