R=6378137; (WGS84椭球) P1_lat=30.4761442132609; p1_lat=P1_lat*pi/180; dlat=p2_lat-p1_lat;
dlon=p2_lon-p1_lon; a=sin(dlat/2)*sin(dlat/2)+cos(p1_lat)*cos(p2_lat)*sin(dlon/2)*sin(dlon/2); c=2*asin(min(1,sqrt(a))); d=R*c; jcstone 2012年4月12 精度不够,R的取值是问题
本方法中R为本地卯酉圈半径N和子午圈半径M的均值R=sqrt(M*N) 椭球为WGS84椭球
精度不及转为空间直角坐标系坐标距离计算
#region 计算地理几何坐标点的距离 /// <summary> /// 近似计算两大地点的距离 /// </summary> /// <param name="StartLocation"></param> /// <param name="EndLocation"></param> /// <returns></returns> public double MeasureDistance(Location StartLocation, Location EndLocation) { //double R =6371000; double R = new EarthEllipsoid(EarthSphereType.WGS1984).Sphere_LocalRadius(StartLocation); return MeasureDistance(StartLocation, EndLocation, R); } /// <summary> /// 近似计算两大地点的距离 /// </summary> /// <param name="StartLocation">起点</param> /// <param name="EndLocation">止点</param> /// <param name="R">本地地球曲率半径</param> /// <returns>距离(米)</returns> public double MeasureDistance(Location StartLocation, Location EndLocation,double R) { DegreeConvert Degreeconvert = new DegreeConvert(); double startlat = Degreeconvert.ToRadianByDeg(StartLocation.Latitude); double endlat = Degreeconvert.ToRadianByDeg(EndLocation.Latitude); double dLat = Degreeconvert.ToRadianByDeg(EndLocation.Latitude - StartLocation.Latitude); double dLon = Degreeconvert.ToRadianByDeg(EndLocation.Longitude - StartLocation.Longitude); double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
Math.Cos(startlat) * Math.Cos(endlat) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2); double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a))); double d = R * c; return d; } /// <summary>
/// 计算大地线(地理坐标点集合)的距离 /// </summary> /// <param name="locations"></param> /// <returns></returns> public double MeasureDistance(LocationCollection locations) { if (locations.Count < 2) return 0; Location center = GetCenterLocation(locations[0], locations[locations.Count - 1]); //本地地球平均曲率半径 double R = new EarthEllipsoid(EarthSphereType.WGS1984).Sphere_LocalRadius(center); //double R =6371000; double length = 0;
for (int i = 0; i < locations.Count - 1; i++) { length = length + MeasureDistance(locations[i], locations[i + 1],R); } return length; } #endregion
[0] = {30.4762317584019,114.337461116389,0}
[1] = {30.4772951042471,114.34328687437,0}
采用上述算法近似计算 = 571.89291808016424
空间直角坐标系 571.68532983587249
SQL2008 计算结果571.685330473182
DECLARE @g geography;
DECLARE @h geography; SET @g = geography::STGeomFromText('POINT(114.337461116389 30.4762317584019)', 4326); SET @h = geography::STGeomFromText('POINT(114.34328687437 30.4772951042471)', 4326); SELECT @g.STDistance(@h); |
|