NetTopologySuite get distance between LineString and Point, using Geography

43 Views Asked by At

I have a LineString and a Point , which used geograhpy type, and i tried to calculate a distance between them:

 

        Coordinate pointCoordinate = new Coordinate(-34.0, 155.0); 
     Coordinate[] lineStringCoordinates = new Coordinate[]
     {
         new Coordinate(-33.0, 150.0),
         new Coordinate(-35.0, 152.0),
         new Coordinate(-34.5, 151.5),
         new Coordinate(-33.5, 151.5),
         new Coordinate(-33.0, 150.0)
     };
    
     // Create the point and LineString geometries
     Point point = new Point(pointCoordinate);
     LineString lineString = new LineString(lineStringCoordinates);
    
     // Use DistanceOp to calculate the geodetic distance
     DistanceOp distanceOp = new DistanceOp(point, lineString);
     double distance = distanceOp.Distance();
    
     Console.WriteLine($"Geodetic distance from point to LineString: {distance} meters");

Unfortunately, isnt correct because DistanceOp is working only with geometry instead of geography.

How to better solve the problem?

0

There are 0 best solutions below