Object model for geospatial calculations and transformations.
$ dotnet add package Tellurian.GeospatialA strongly-typed, high-performance .NET library for geospatial calculations. Zero heap allocations - all types are value types optimized for tracking and real-time applications.
dotnet add package Tellurian.Geospatial
var stockholm = Position.FromDegrees(59.3262, 17.8420);
var london = Position.FromDegrees(51.5074, -0.1278);
var stretch = Stretch.Between(stockholm, london);
Console.WriteLine($"Distance: {stretch.Distance.Kilometers:F0} km"); // 1435 km
Console.WriteLine($"Direction: {stretch.Direction.Degrees:F1}°"); // 236.5°
Console.WriteLine($"Initial bearing: {stretch.InitialBearing.Degrees:F1}°"); // 227.5°
var start = Position.FromDegrees(58.0338, 11.7450);
var bearing = Angle.FromDegrees(97);
var distance = Distance.FromMeters(562);
var destination = start.Destination(bearing, distance);
// Position: 58.0332, 11.7545
var center = Position.FromDegrees(58.0724, 11.8233);
var geofence = new CircularSurface(center, Distance.FromMeters(100));
var vehicle = Position.FromDegrees(58.0725, 11.8235);
if (geofence.Includes(vehicle))
{
Console.WriteLine("Vehicle is inside the geofence");
}
var routeStart = Position.FromDegrees(58.0338, 11.7450);
var routeEnd = Position.FromDegrees(58.0332, 11.7545);
var route = Stretch.Between(routeStart, routeEnd);
var currentPosition = Position.FromDegrees(58.0333, 11.7502);
var crossTrack = route.CrossTrackDistance(currentPosition); // Distance from route
var onTrack = route.OnTrackDistance(currentPosition); // Progress along route
Console.WriteLine($"Off track: {crossTrack.Meters:F1} m"); // 15.9 m
Console.WriteLine($"Progress: {onTrack.Meters:F0} m"); // 311 m
// Convert GPS coordinates to Swedish grid (SWEREF99 TM)
var gpsPosition = Position.FromDegrees(59.3262, 17.8420);
var gridCoord = GaussKreugerTransformer.ToGridCoordinate(gpsPosition, MapProjections.Sweref99TM);
Console.WriteLine($"N: {gridCoord.X}, E: {gridCoord.Y}");
// Convert back to GPS coordinates
var backToGps = GaussKreugerTransformer.ToPosition(gridCoord, MapProjections.Sweref99TM);
| Type | Description |
|---|---|
Position | Latitude/Longitude coordinate |
Stretch | Segment between two positions with distance, direction, and bearing calculations |
Distance | Value in meters/kilometers with comparison tolerance |
Angle | Value in degrees/radians (0-360°) |
Speed | Value in m/s or km/h |
Vector | Distance with direction |
| Type | Description |
|---|---|
CircularSurface | Circle defined by center position and radius |
PolygonalSurface | Polygon defined by border positions |
Both implement Includes(Position) to check if a point is inside the boundary.
Map Projections: UTM zones 32-35, Sweref99TM, RT90
Ellipsoids: WGS84, GRS80, Hayford1910
The default HaversineDistanceCalculator is optimized for tracking applications (accurate to decimeters).
Implement IDistanceCalculator for custom algorithms.
Inspired by Latitude/longitude spherical geodesy tools by Chris Veness.
Coordinate transformation based on formulas from Swedish Land Survey (Lantmäteriet).
MIT License - see LICENSE for details.
ToString() output changed for Angle, Latitude, Longitude, Position, Vector, and StretchPosition.FromDegrees())