简体   繁体   中英

Calculate distance between to points(lat, lon) with NetTopologySuite

I followed this article https://docs.microsoft.com/en-us/ef/core/modeling/spatial but is not working.

var seattle = new Point(-122.333056, 47.609722) { SRID = 4326 };
var redmond = new Point(-122.123889, 47.669444) { SRID = 4326 };

var distance = seattle.ProjectTo(2855).Distance(redmond.ProjectTo(2855));

This code is returning distance = 17062 meters

From websites Distance Calculator I'm getting distance = 17.02 kilometers

The distance is approximately the same for the example in the article.

But if I choose this coordinates:

var seattle = new Point(1.230469, 19.973349) { SRID = 4326 };
var redmond = new Point(17.753906, 19.642588) { SRID = 4326 };

var distance = seattle.ProjectTo(2855).Distance(redmond.ProjectTo(2855));

This code is returning distance = 1926891 meters

From websites, distance = 1,728 kilometers

The difference is 200 meters approx. I tested with other locations and the results are worse

In the article there is a comment: // Different data requires a different coordinate system.

What does it mean? Should I use another coordinate system than 2855? Which one?

Have a look at UTM Zones ( Univesal Transverse Mercator ) as a starting point: 在此处输入图片说明

Generally, the smaller the region of the 3D earth you try to project onto a 2D map, the more accurate it will be. So in Microsoft's example, you could get okay accuracy using UTM 10 for seattle , but they are being even more precise using a specific Northern Washington projection

So for your case (Mali), try UTM 31 . Make sure to copy the "Well Known Text" (WKT) into your example and reference that instead of the one for Northern Washington. Then, if that's not good enough, try searching for projections closer to your precise area of interest.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM