.NET Coordinates

This C# library can be used to convert from one mapping coordinate system to another, for instance converting latitude/longitude to UK OS coordinates. It is based on the JCoord class library, which seems to have gone offline but was released under a GPL license, so this library is also licensed under the GPL.

GitHub logo Download/view the source code (requires Visual Studio 2019)
Download the assembly (.NET Standard 2.0)

Read the documentation

And here's a simple example of usage. Other than changing the datum, the classes are immutable i.e Their state does not change after instantiation. They have methods to convert to other coordinate systems which return an instance of the required type.

using System;
using DotNetCoords;

namespace TestDotNetCoords
{
  class Program
  {
    static void Main(string[] args)
    {
      // create an OS grid reference object
      OSRef osRef = new OSRef(535598, 182120);
      Console.WriteLine("OS reference is " + osRef.ToString());
      Console.WriteLine("Grid reference is " + osRef.ToSixFigureString());

      LatLng latLng = osRef.ToLatLng();
      Console.WriteLine("Lat/long using OSGB36 datum is " + latLng.ToString());

      latLng.ToWGS84();
      Console.WriteLine("Lat/long using WGS84 datum is " + latLng.ToString());

      MGRSRef mgrsRef = latLng.ToMGRSRef();
      Console.WriteLine("MGRS reference is " + mgrsRef.ToString());

      UTMRef utmRef = mgrsRef.ToUTMRef();
      Console.WriteLine("UTM reference is " + utmRef.ToString());

      Console.ReadLine();
    }
  }
}

Change History

1.0.0.23
.NET Coords is now a .NET Standard 2.0 project, meaning it can be used in .NET Framework 4.8 and .NET Core projects

1.0.0.22
Added the ITMRef class that represents a Irish Transverse Mercator (ITM) reference

1.0.0.21
Added a new ToString overload MGRSRef that accepts a format string

1.0.0.20
Fixed a bug in ToDatum() (thanks to Damir Stoic for spotting it)

1.0.0.19
Added LatLng.Bearing that returns the bearing between two LatLng objects

1.0.0.18
Added a new overload of LatLng.ToUtmRef to force the longitude zone used

1.0.0.17
Fixed a bug in the IrishRef constructor and more clean up.
Removed some property setters to improve API consistency

1.0.0.16
Cleaned up the code with ReSharper

1.0.0.15
Added OSRef.ToTenFigureString() method to generate 10 figure OS grid references.

1.0.0.14
OSRef constructor now accepts 6, 8 and 10 figure OS grid references.

1.0.0.13
Better OSRef and IrishRef constructors that take a LatLng, so the LatLng does not have to be using the WGS84 datum.

1.0.0.12
Added support for ED50 datum.

1.0.0.11
Fixed ToDatum() so it works in more cases (not just when converting from WGS84)
New LatLng copy constructor

1.0.0.10
Added a better performing MGRSRef constructor (thanks to Vincent de Lagabbe)

1.0.0.9
Added helper methods to check validity of latitude/longitudes
Improved the formatting of UTMRef.ToString() method

1.0.0.8
Fixed the UTMRef.ToString() method (thanks to Bryan McCauley for providing the fix)

1.0.0.7
Added Windows Phone class library (thanks to Timothy Green for the suggestion)

1.0.0.6
Fixed LatLng constructor which takes degrees. minutes and seconds to handle the correct range.
Fixed OSRef constructor taking a grid reference so it doesn't throw an exception

1.0.0.5
MGRSRef constructor taking a single string now works.
MGRSRef constructor with parameters for each part of the MGRS reference no longer throws an exception
MGRSRef conversion to UTM reference now works for more cases

1.0.0.4 - MGRSRef.ToUTMRef() should now work
1.0.0.3 - Fixed a bug in MGRSRef.ToString()
1.0.0.2 - Added generic versions of Datum and Ellipsoid classes to reduce code size
1.0.0.1 - Initial release