GeographicLib.NET
2.0.0
See the version list below for details.
dotnet add package GeographicLib.NET --version 2.0.0
NuGet\Install-Package GeographicLib.NET -Version 2.0.0
<PackageReference Include="GeographicLib.NET" Version="2.0.0" />
<PackageVersion Include="GeographicLib.NET" Version="2.0.0" />
<PackageReference Include="GeographicLib.NET" />
paket add GeographicLib.NET --version 2.0.0
#r "nuget: GeographicLib.NET, 2.0.0"
#:package GeographicLib.NET@2.0.0
#addin nuget:?package=GeographicLib.NET&version=2.0.0
#tool nuget:?package=GeographicLib.NET&version=2.0.0
GeographicLib.NET
GeographicLib is a small set of C++ classes for performing conversions between geographic, UTM, UPS, MGRS, geocentric, and local cartesian coordinates,for gravity (e.g., EGM2008), geoid height and geomagnetic field (e.g., WMM2020) calculations, and for solving geodesic problems.
GeographicLib.NET is a native .NET implementation of GeographicLib written in pure C#.
What's different from NETGeographicLib
Unlike NETGeographicLib, GeographicLib.NET is implemented in pure C# without binding the C++ GeograpbicLib library by using C++/CLI or P/Invoke, thus achieves higher level of portability.
You should be able to use GeographicLib.NET with any target framework and platform that supports .NET Standard 2.0 or above.
Features
Bellow is a list of implemented features.
- Projections (
AlbersEqualArea,AzimuthalEquidistant,CassiniSoldner,Gnomonic,LambertConformalConic,PolarStereographicandTransverseMercator) - Geocodes (
GARS,Geohash,Georef,MGRSandOSGB) - Coordinate conversions (
UTMUPS,GeocentricandLocalCartesian) - Coordinate parsing/formatting (
DMSandGeoCoords) - Geodesic (
Geodesic,GeodesicLine,GeodesicExactandGeodesicLineExact) - Rhumb (
RhumbandRhumbLine) - PolygonArea (
PolygonArea<T>,PolygonArea,PolygonAreaExactandPolygonAreaRhumb) - Geoid (
Geoid) - GravityModel (
GravityCircle,NormalGravityandGravityModel) - MagneticModel (
MagneticModel,MagneticCircle) - Auxilary classes (
MathEx,Ellipoid,EllipticFunctionandSphericalHarmonic)
Geodesic and GeodesicExact are tested with the test set for geodesic.
TransverseMercator and TransverseMercatorExact are tested with data generated by 64-bit TransverseMercatorProj utility ran on Windows.
Managed implemetation of C mathematical functions in MathEx are tested with data generated by 64-bit Windows Universal C Runtime.
Installing
Stable 
Stable releases of GeographicLib.NET are hosted on NuGet. You can install them using the following command:
dotnet add package GeographicLib.NET
Preview 
Preview versions of GeographicLib.NET are hosted on NuGet pre-release channel. You can install them using the following command:
dotnet add package GeographicLib.NET --prerelease
Mathematical Functions
GeographicLib uses several C mathematical functions that are not available in all versions of .NET. These functions are:
- remquo
- hypot
- log1p
- expm1
- frexp
- log2 (available since .NET 5.0)
- fma (available since .NET 5.0)
- scalbn (available since .NET 5.0)
- copysign (available since .NET 5.0)
- atanh (available since .NET Standard 2.1)
- asinh (available since .NET Standard 2.1)
- cbrt (available since .NET Standard 2.1)
GeographicLib.NET provides managed implementations of these functions (ported from musl libc).
GeographicLib.MathEx class will use implementations provided by .NET runtime whenever possible, and will fallback to managed implementations when not available in .NET runtime.
You can also force GeographicLib.MathEx to fallback to platform dependent implementations provided by system C runtime libraries,
rather than managed implementations, by setting GeographicLib.MathEx.UseManagedCMath property to false.
Native C math implemenation may provide slightly better performance, but also produce inconsistent results on different platforms in some edge cases.
In fact, the performance of different C math implementations are very close, managed implementation performs even better on newer runtimes. The following table shows the benchmark result of Geodesic.WGS84.GenDirect executed with/without manged C math:
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
Intel Xeon CPU E5-2689 0 2.60GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK=6.0.300-preview.22204.3
[Host] : .NET 6.0.4 (6.0.422.16404), X64 RyuJIT
.NET 5.0 : .NET 5.0.16 (5.0.1622.16705), X64 RyuJIT
.NET 6.0 : .NET 6.0.4 (6.0.422.16404), X64 RyuJIT
.NET Core 2.1 : .NET Core 2.1.30 (CoreCLR 4.6.30411.01, CoreFX 4.6.30411.02), X64 RyuJIT
.NET Core 3.1 : .NET Core 3.1.24 (CoreCLR 4.700.22.16002, CoreFX 4.700.22.17909), X64 RyuJIT
| Method | Job | Runtime | UseManagedCMath | Mean | Error | StdDev | Ratio | RatioSD |
|---|---|---|---|---|---|---|---|---|
| Direct | .NET 5.0 | .NET 5.0 | False | 953.1 ns | 14.94 ns | 13.98 ns | 0.82 | 0.01 |
| Direct | .NET 6.0 | .NET 6.0 | False | 975.3 ns | 6.42 ns | 6.00 ns | 0.84 | 0.01 |
| Direct | .NET Core 2.1 | .NET Core 2.1 | False | 1,206.1 ns | 9.08 ns | 8.49 ns | 1.03 | 0.01 |
| Direct | .NET Core 3.1 | .NET Core 3.1 | False | 1,166.3 ns | 15.07 ns | 14.10 ns | 1.00 | 0.00 |
| Direct | .NET 5.0 | .NET 5.0 | True | 927.6 ns | 13.46 ns | 12.59 ns | 0.78 | 0.01 |
| Direct | .NET 6.0 | .NET 6.0 | True | 974.9 ns | 16.03 ns | 14.99 ns | 0.82 | 0.01 |
| Direct | .NET Core 2.1 | .NET Core 2.1 | True | 1,242.1 ns | 10.02 ns | 8.88 ns | 1.04 | 0.01 |
| Direct | .NET Core 3.1 | .NET Core 3.1 | True | 1,195.6 ns | 8.08 ns | 7.56 ns | 1.00 | 0.00 |
Thus it's recommended to stick with managed C math until it becomes a performance bottleneck of your application, as it's more consistent as compared to native C math on different platforms.
Documentation
GeographicLib.NET includes a detailed XML documentation for all public APIs. Since the API surface of GeographicLib.NET is highly compatible with GeographicLib, you can also refer the its documentation here for usage and detailed explanation.
Change Log
GeographicLib.NET adopts changes made in GeographicLib and aligns its version number with GeographicLib releases.
Bellow is a list of stable releases of GeographicLib.NET and changes made in .NET side in each release. For changes adopted from GeographicLib, please refer the its change log here.
Version 2.0.0 (released 2022/08/24)
- NEW
- Add
IPolygonAreainterface to provide better support for unit testing and dependency injection. - Add
CountandIsPolylineproperties (corresponding toNumPointsandPolylinemethods in GeographicLib) toPolygonArea. - Add a new method
Utility.FractionalYearwhich can parse floating point number and date time string as fractional year. - Allow constructing
GeoidfromStreamand byte array.
- Add
- FIX
- String accepting APIs now handle lowercase "nan" correctly.
- Ensure consistent rounding mode (
MidpointRounding.ToEven) across different runtimes when converting floating point number to string. MGRS.Reversenow allows lowercase input.
Version 1.52.1 (released 2022/04/12)
NEW
- Target .NET 6.0 in addition to .NET 5.0, .NET Standard 2.1 and .NET Standard 2.0.
- Source Link support.
BREAKING
- Fixed typos in
Ellipsoid. (RenamedSecondFlatterningtoSecondFlatteningandThirdFlatterningtoThirdFlattening)
- Fixed typos in
FIX
- Fixed an issue that
Freezemethod inAlbersEqualArea,LambertConformalConicandPolarStereographicwas not working correctly. - Fixed duplicate instantiation of
WGS84andGRS80static properties defined inNormalGravity. - Add missing support for World Magnetic Model Format v2.
- Fixed an issue that
Version 1.52.0 (released 2021/07/07)
BREAKING
- Modify overloads of
ForwardandReverseinAlbersEqualArea,AzimuthalEquidistant,CassiniSoldnerandLambertConformalConicto return coordinates as tuples. - Modify methods using
outparameters defined inNormalGravity,GravityModel,GravityCircle,MagneticModelandMagnegticCircleto return results as tuples.
- Modify overloads of
NEW
- Add constructor overloads that accept
IEllipsoidas parameter forAlbersEqualAreaandLambertConformalConic. - Add managed implementation of
log2. - Add overloads of
DirectandInverseinGeodesic/GeodesicLine,GeodesicExact/GeodesicLineExactandRhumb/RhumbLineExact, that return the computation results as a single object. - Add definitions of popular reference ellipsoids in
Ellipsoidclass.
- Add constructor overloads that accept
FIX
- Fix stack overflow bug for
Forward(double lon0, double lat, double lon)andReverse(double lon0, double x, double y)inTransverseMercatorExact.
- Fix stack overflow bug for
Version 1.51.0 (released 2021/03/14)
Initial stable release.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Memory (>= 4.5.4)
- System.Runtime.Extensions (>= 4.3.1)
-
.NETStandard 2.1
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on GeographicLib.NET:
| Repository | Stars |
|---|---|
|
drewnoakes/metadata-extractor-dotnet
Extracts Exif, IPTC, XMP, ICC and other metadata from image, video and audio files
|