Is there a .NET library to calculate area enclosed by polygon made up of geo coordinates (lat longs)?


SharpMap has a polygon class with an Area method. But before calling that, you should consider projecting the polygon's coordinates into an equal area projection to yield meaningful results. It looks like SharpMap uses ProjNet, which has Albers, but I also see there is now a c# wrapper for Proj4.


NetTopologySuite offer what you need, and much more: http://code.google.com/p/nettopologysuite/

  • +1 I'd forgotten about nettopologysuite, looks like it has a lot more momentum than SharpMap. – Kirk Kuykendall Oct 2 '11 at 21:06

Another option is using the Microsoft.SqlServer.Types library. While it isn't supplied in .NET, it is available as a nuget package, or you can find it in your SqlServer (or Express) installation (%programfiles%\Microsoft SQL Server\100\SDK\Assemblies) as Microsoft.SqlServer.Types.dll

Obviously, it relies on Microsoft (and the SQL types library which could have it's own licencing issues), so the other options supplied may well be better options, but if you are already integrating with SqlServer 2008, then this may be a nice way to go.

To do an area calculation is pretty simple (I have included an NUnit test below demonstrating it.

using System;
using System.Text;
using Microsoft.SqlServer.Types;
using System.Data.SqlTypes;
using NUnit.Framework;

namespace YourNamespace
    class GeometryTest

        public void CheckAreaTest()
            string polygon = "POLYGON((145 -42 , 147 -42, 147 -40, 145 -40, 145 -42))"; //wkt string over Tasmania, Australia
            SqlGeography geom = new SqlGeography();
            SqlChars geometryString = new SqlChars(new SqlString(polygon));
            geom = SqlGeography.STPolyFromText(geometryString, 4326);
            Assert.AreEqual(37371149986.1, Math.Round(geom.STArea().Value, 1));


  • While your example helps achieve find the area but it doesn't address the part where I said that I have lat, longs because area needs to be calculated in meters. – Muhammad Hasan Khan Oct 3 '11 at 2:55
  • By using SqlGeography, the STArea is automatically in square metres (which is why it is so big). Will ammend to give better values in the string polygon string to avoid confusion. – Kelso Oct 3 '11 at 3:17
  • Try the following that maps approximately to utah's boundary..You will get a value 509850820193573 that's about the size of the Earth's surface area: "POLYGON((-114.1142489 37.12741587,-114.0703035 41.87154978,-111.0380770 42.10020423,-110.9501864 41.08136450,-109.1484285 40.98191446,-109.1044832 37.12741587,-109.1044832 37.0573086,-114.1142489 37.12741587))" – arviman Apr 26 '17 at 11:38

Link to System.Data.Entity.dll and use the DbGeography object such as:

DbGeography geography = DbGeography.FromText(wktString);
double? myArea = geography.Area;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.