Joa*_*mer 12 geometry gps geospatial
我目前正在处理gps数据和精确的高度测量.我想计算两个连续点之间的距离.有很多关于使用WGS84椭圆体等计算两点之间距离的信息.
但是,我没有找到任何将海拔高度变化考虑在内的距离计算信息.
有没有人知道一些描述这种方法的网站,论文,书籍等?谢谢
编辑:Sql Server 2008地理扩展也在计算距离时忽略高度信息.
我使用起始高度和结束高度的平均值作为恒定高度来实现WGS84距离函数.如果您确定沿着您的路径会有相对较小的高度变化,这可以很好地工作(误差是相对于您的两个LLA点的高度差).
这是我的代码(C#):
/// <summary>
/// Gets the geodesic distance between two pathpoints in the current mode's coordinate system
/// </summary>
/// <param name="point1">First point</param>
/// <param name="point2">Second point</param>
/// <param name="mode">Coordinate mode that both points are in</param>
/// <returns>Distance between the two points in the current coordinate mode</returns>
public static double GetGeodesicDistance(PathPoint point1, PathPoint point2, CoordMode mode) {
// calculate proper geodesics for LLA paths
if (mode == CoordMode.LLA) {
// meeus approximation
double f = (point1.Y + point2.Y) / 2 * LatLonAltTransformer.DEGTORAD;
double g = (point1.Y - point2.Y) / 2 * LatLonAltTransformer.DEGTORAD;
double l = (point1.X - point2.X) / 2 * LatLonAltTransformer.DEGTORAD;
double sinG = Math.Sin(g);
double sinL = Math.Sin(l);
double sinF = Math.Sin(f);
double s, c, w, r, d, h1, h2;
// not perfect but use the average altitude
double a = (LatLonAltTransformer.A + point1.Z + LatLonAltTransformer.A + point2.Z) / 2.0;
sinG *= sinG;
sinL *= sinL;
sinF *= sinF;
s = sinG * (1 - sinL) + (1 - sinF) * sinL;
c = (1 - sinG) * (1 - sinL) + sinF * sinL;
w = Math.Atan(Math.Sqrt(s / c));
r = Math.Sqrt(s * c) / w;
d = 2 * w * a;
h1 = (3 * r - 1) / 2 / c;
h2 = (3 * r + 1) / 2 / s;
return d * (1 + (1 / LatLonAltTransformer.RF) * (h1 * sinF * (1 - sinG) - h2 * (1 - sinF) * sinG));
}
PathPoint diff = new PathPoint(point2.X - point1.X, point2.Y - point1.Y, point2.Z - point1.Z, 0);
return Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y + diff.Z * diff.Z);
}
Run Code Online (Sandbox Code Playgroud)
在实践中,我们发现高度差异很少产生很大的差异,我们的路径通常为1-2km长,高度在100m的数量级上变化,我们看到平均变化约为5m,与使用未经修改的WGS84椭球相比.
编辑:
要添加到这一点,如果你不希望较大的高度变化,您可以将您的WGS84坐标ECEF(地球为中心的地球固定)和在我的函数的底部显示评估直线路径.将点转换为ECEF很简单:
/// <summary>
/// Converts a point in the format (Lon, Lat, Alt) to ECEF
/// </summary>
/// <param name="point">Point as (Lon, Lat, Alt)</param>
/// <returns>Point in ECEF</returns>
public static PathPoint WGS84ToECEF(PathPoint point) {
PathPoint outPoint = new PathPoint(0);
double lat = point.Y * DEGTORAD;
double lon = point.X * DEGTORAD;
double e2 = 1.0 / RF * (2.0 - 1.0 / RF);
double sinLat = Math.Sin(lat), cosLat = Math.Cos(lat);
double chi = A / Math.Sqrt(1 - e2 * sinLat * sinLat);
outPoint.X = (chi + point.Z) * cosLat * Math.Cos(lon);
outPoint.Y = (chi + point.Z) * cosLat * Math.Sin(lon);
outPoint.Z = (chi * (1 - e2) + point.Z) * sinLat;
return outPoint;
}
Run Code Online (Sandbox Code Playgroud)
编辑2:
我被问到代码中的一些其他变量:
// RF is the eccentricity of the WGS84 ellipsoid
public const double RF = 298.257223563;
// A is the radius of the earth in meters
public const double A = 6378137.0;
Run Code Online (Sandbox Code Playgroud)
LatLonAltTransformer
是一个我用来从LatLonAlt坐标转换为ECEF坐标的类,并定义了上面的常量.