如何在 NetTopologySuite 中通过米计算两个几何距离?
how to calculate two geometry distance via meters in NetTopologySuite?
我使用 PGSQL 获取几何数据。
var hca = new WKTReader().Read(
$"SRID=4326;{hcaShape}");
var point = new GeometryFactory().CreatePoint(new Coordinate(x, y));
var res = hca.Distance(point)
结果显示为:'0.00009xxx'
但是我要米
同样重要的是这种情况不是点对点。
如何将结果转换为米?(我是 NetTopologySuite 的新手)
我通过使用 ProjNet 将几何图形投影到度量 CoordinateSystem
来完成此任务
public static NetTopologySuite.Geometries.Geometry ProjectGeometry(NetTopologySuite.Geometries.Geometry geom,
string fromWkt, string toWkt)
{
var sourceCoordSystem = new CoordinateSystemFactory().CreateFromWkt(fromWkt);
var targetCoordSystem = new CoordinateSystemFactory().CreateFromWkt(toWkt);
var trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(sourceCoordSystem,
targetCoordSystem);
var projGeom = Transform(geom, transform: trans.MathTransform);
return projGeom;
}
我使用 PGSQL 获取几何数据。
var hca = new WKTReader().Read(
$"SRID=4326;{hcaShape}");
var point = new GeometryFactory().CreatePoint(new Coordinate(x, y));
var res = hca.Distance(point)
结果显示为:'0.00009xxx' 但是我要米
同样重要的是这种情况不是点对点。 如何将结果转换为米?(我是 NetTopologySuite 的新手)
我通过使用 ProjNet 将几何图形投影到度量 CoordinateSystem
public static NetTopologySuite.Geometries.Geometry ProjectGeometry(NetTopologySuite.Geometries.Geometry geom,
string fromWkt, string toWkt)
{
var sourceCoordSystem = new CoordinateSystemFactory().CreateFromWkt(fromWkt);
var targetCoordSystem = new CoordinateSystemFactory().CreateFromWkt(toWkt);
var trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(sourceCoordSystem,
targetCoordSystem);
var projGeom = Transform(geom, transform: trans.MathTransform);
return projGeom;
}