R=6378137; (WGS84橢球)
P1_lat=30.4761442132609;
P1_lon=114.335983525027;
P2_lat=30.4792925569965;
P2_lon=114.343405206746;
p1_lat=P1_lat*pi/180;
p2_lat=P2_lat*pi/180;
p1_lon=P1_lon*pi/180;
p2_lon=P2_lon*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) 橢球?yàn)閃GS84橢球
精度不及轉(zhuǎn)為空間直角坐標(biāo)系坐標(biāo)距離計(jì)算
#region 計(jì)算地理幾何坐標(biāo)點(diǎn)的距離
/// <summary>
/// 近似計(jì)算兩大地點(diǎn)的距離
/// </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>
/// 近似計(jì)算兩大地點(diǎn)的距離
/// </summary>
/// <param name="StartLocation">起點(diǎn)</param>
/// <param name="EndLocation">止點(diǎn)</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>
/// 計(jì)算大地線(地理坐標(biāo)點(diǎn)集合)的距離
/// </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}
采用上述算法近似計(jì)算 = 571.89291808016424
空間直角坐標(biāo)系 571.68532983587249
SQL2008 計(jì)算結(jié)果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);