.NET core library with basic geospatial operations such as distance calculation or conversion. Feel free to reach out if operations are missing or better, do a pull request!
This library is available on nuget.
To install it via the package manager:
PM> Install-Package GeoSpatial4Net
Compute the distance (in meters by default) between two coordinates using the Haversine formula:
var coord1 = new Coordinate(36.12, -86.67);
var coord2 = new Coordinate(33.94, -118.4);
var distCalc = new GeoDistanceCalculator();
var computedDistance = distCalc.HaversineDistance(coord1, coord2);
You can also call the method directly with the 2 points' latitude/longitude:
var distCalc = new GeoDistanceCalculator();
var computedDistance2 = distCalc.HaversineDistance(36.12, -86.67, 33.94, -118.4);
By default, the GeoDistancecCalculator return distances in meters,the base unit of length in the International System of Units. If you need distances in other units, specify the unit in the constructor:
var distCalc = new GeoDistanceCalculator(DistanceUnit.Mile);
var computedDistanceInMiles = distCalc.HaversineDistance(36.12, -86.67, 33.94, -118.4);
The supported distance units are:
- meter (default)
- kilometer
- mile
- feet
If needed, you can convert directly distances from one unit to another:
var distanceConverter = new DistanceConverter();
// converts 1500 meters in miles
var distanceM = distanceConverter.ConvertDistance(1500, DistanceUnit.Meter, DistanceUnit.Mile);
If you are looking a ready-to-use solution for geospatial operations, you can check out proximity-map. For any address, find easily the closest location in a set of pre-defined addresses (flying and driving distances).