2

I've been using DbGeography in C# to calculate length and area of WKT geometries (geographies), like this:

var polygon = DbGeography.FromText(wkt, 4326);
var area = polygon.Area;
var line = DbGeography.FromText(wkt2, 4326);
var length = line.Lenght;

How can I achieve this using NetTopologySuite? My WKTs represent lat/longs in degrees. Are there any existing implementations?

Alcibiades
  • 335
  • 5
  • 16

1 Answers1

0

Yes, it is possbile to convert from WKT to Geometry data types using the WKTReader and is explained in the Documentation here: Link

An example of how to use it would be:

public class GeographyHelper
{
    private static GeometryFactory _geometryFactory
    {
        get
        {
            return NetTopologySuite.NtsGeometryServices.Instance.CreateGeometryFactory(4326);
        }
    }

    public void CheckArea()
    {
        var wellKnownTextPoly = "YOUR POLYGON WKT";
        var wellKnownTextLine = "YOUR LINE WKT";

        var rdr = new NetTopologySuite.IO.WKTReader();
        var geometry = rdr.Read(wellKnownTextPoly);

        var polygon = _geometryFactory.CreatePolygon(geometry.Coordinates);
        var area = polygon.Area;

        var lineGeometry = rdr.Read(wellKnownTextLine);
        var line = _geometryFactory.CreateLineString(lineGeometry.Coordinates);
        var length = line.Length;
    }
}
Dawood Awan
  • 7,051
  • 10
  • 56
  • 119