0

I use PGSQL to get geometry data.

 var hca = new WKTReader().Read(
        $"SRID=4326;{hcaShape}");
 var point = new GeometryFactory().CreatePoint(new Coordinate(x, y));
 var res = hca.Distance(point)

The result Shows like:'0.00009xxx' But I want meters.

Also important thing is this case is not point to point. How to convert result to meters?(I'm new with NetTopologySuite)

Fush1
  • 93
  • 1
  • 7

1 Answers1

0

I completed this task by using ProjNet to project the geometries to a metric 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;
}
FObermaier
  • 832
  • 5
  • 12
Fush1
  • 93
  • 1
  • 7