验证结果如下:
116.66885608202652 116.05364820797979 114.28764035412392 111.60513634687186 108.37944785253909 105.09000981559511 102.2637861494519 100.38650671049055 99.79581077763879 100.59276661692931 102.61595683755391 105.4929026708211 108.73914573002186 111.85882184494989 114.41831613054764 116.0891677559819 116.66885608202652 116.0891677559819 114.41831613054846 111.85882184495108 108.73914573002347 105.4929026708211 102.61595683755391 100.59276661692915 99.7958107776412 100.38650671049055 102.26378614945223 105.09000981559511 108.37944785253909 111.60513634687305 114.28764035412605 116.05364820797979 116.66885608202652大部分结果都超过了 100 千米,并且误差超过了 10 千米。比较妥善的方式就是计算多个方向的距离,然后取一个平均值。
public static double AverageDistance(double lat,double lon,double distance,int part) { var seg = 360 / part; var rs = new List<double>(); var raw = new Coordinate(lat, lon); for (var i = 0; i < 360; i += seg) { var move = ConvertEarthDToPlaneXY(lat, lon, distance, i); var r = raw.Distance(new Coordinate(move[0], move[1])); rs.Add(r); } return rs.Average(); }上述缓冲区的距离计算改为:
// 取4个方向(0°、90°、180°和270°)对应的距离,然后求均值 var hqR = AverageDistance(hongqiao.X, hongqiao.Y, 100000,4);得出的结果如下:
108.4796420377765 107.90879824241405 106.26991268291549 103.77978023046698 100.78401282732902 97.7268731801004 95.09732271673099 93.34698897092896 92.79099574532 93.52530908781738 95.401788528952 98.07519029469032 101.09498625442704 103.9991018274525 106.38288739908288 107.93950641121064 108.4796420377765 107.93950641121104 106.38288739908288 103.9991018274531 101.09498625442863 98.07519029469222 95.40178852895636 93.5253090878196 92.7909957453224 93.34698897093132 95.09732271673535 97.72687318010274 100.78401282733111 103.7797802304676 106.26991268291549 107.90879824241446 108.4796420377765从结果中可以看出,误差控制在 10 千米之内。
上述计算的是一个点的缓冲区,如果是 LineString 或者 Polygon 的缓冲区,则尽可能的取其上不同的点进行距离转换后求取均值。
五、总结总的来说,结合 CoordinateSharp 与 NetTopologySuite 可以进行许多有用的计算。但是误差也不可避免,特别是纬度较高的时候。
如果各位有其他更好的解决方案,希望提交评论。