JMK*_*JMK 8 c# geometry nettopologysuite
每当我使用 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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何将从 NetTopologySuite 返回的值准确地转换为英里/距离?这是我不知道的某种形式的 GPS 距离装置吗?
谢谢
小智 9
正如 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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5050 次 |
| 最近记录: |