i'm using GeoJSON.Net library ( https://github.com/GeoJSON-Net/GeoJSON.Net ) to create some GeoJSON features in my code. Points, multilines etc. All that works fine until i need to calculate distance between some pair of features. This library does not have any ability to do that.
I've tried using GeoJSON.Net.Contrib.MsSqlSpatial (https://www.nuget.org/packages/GeoJSON.Net.Contrib.MsSqlSpatial ) to convert features to SqlGeographies and then use the method on that type to calculate the distance. That works perfectly with one caveat: it's .NET Framework-only. The library is not available for .NET Core.
Please note, that I need an ability to calculate distance between two arbitrary features - points, multilines, polygons and not just between two points. This has to be done for SRID 4326 (WGS84).
Any idea?
Best regards, Dmytro.
GeoJSON.Net is just a library to de-serialize GeoJSON according to RFC 7946.
For calculating distances you could either write your own implementation, or use one of the existing libraries like Geolocation .
For convenience you can write some extension methods.
public static class PositionExtension
{
public static double GetDistanceTo(this Position origin, Position destination,
DistanceUnit unit = DistanceUnit.Kilometers)
{
return GeoCalculator.GetDistance(
origin.Latitude, origin.Longitude,
destination.Latitude, destination.Longitude, distanceUnit: unit);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.