I am trying to calculate the area of a polygon using the NetTopologySuite version 2.5.0 in meters squared.
var gf_4326 = NetTopologySuite.NtsGeometryServices.Instance.CreateGeometryFactory(4326);
var ply1 = gf_4326.CreatePolygon(new[] {
new NetTopologySuite.Geometries.Coordinate(-37.736229, 144.998645),
new NetTopologySuite.Geometries.Coordinate(-37.735903, 144.998704),
new NetTopologySuite.Geometries.Coordinate(-37.73591958016702, 144.9988860085938),
new NetTopologySuite.Geometries.Coordinate(-37.736248, 144.998830),
new NetTopologySuite.Geometries.Coordinate(-37.736229, 144.998645),
});
double area = ply1.Area;
In this example the area is not in meters squared. The area is 6.106743190353325E-08 but should be the size of a suburban property. This is orders of magnitude too low.
What am I doing wrong?
Rather than use the ProjNet (no longer maintained) as recommended in this Microsoft article, I opted to use the .net library that Microsoft uses in sql server to do these calculations. I found this much easier than using ProjNet and adding various well known strings to do the projections.
This code depends on the Microsoft.SqlServer.Types and Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite nuget packages.
To use the extension method: