GPS定位的偏移校正(WGS84与火星坐标互转)
作者:互联网
原文:GPS定位的偏移校正(WGS84与火星坐标互转)
地图坐标系目前包括:
地球坐标 (WGS84)
WGS84:World Geodetic System 1984,是为GPS全球定位系统使用而建立的坐标系统。
- 国际标准,从 GPS 设备中取出的数据的坐标系
- 国际地图提供商使用的坐标系
火星坐标 (GCJ-02)也叫国测局坐标系
GCJ-02是由中国国家测绘局(民间说的火星坐标系)制订的地理信息系统的坐标系统。
它是一种对经纬度数据的加密算法,即加入随机的偏差。
国内出版的各种地图系统(包括电子形式),必须至少采用GCJ-02对地理位置进行首次加密。
- 中国标准,从国行移动设备中定位获取的坐标数据使用这个坐标系
- 国家规定: 国内出版的各种地图系统(包括电子形式),必须至少采用GCJ-02对地理位置进行首次加密。
public class Wgs2MarsService { private readonly static double[] Lx = new double[297000]; private readonly static double[] Ly = new double[297000]; static Wgs2MarsService() { string str = string.Empty; List<string> points = new List<string>(); using (StreamReader sr = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GPS.CoordinatesTransformation.txt"))) { str = sr.ReadLine(); while (!string.IsNullOrEmpty(str)) { points.Add(str); str = sr.ReadLine(); } } int num = 0; foreach (string s in points) { if (Lx[num] == 0.0) { Lx[num] = (double)int.Parse(s) / 100000.0; } else { Ly[num] = (double)int.Parse(s) / 100000.0; num++; } } } private int ID(int i, int j) { return i + 660 * j; } public bool Wgs2Mars(double latwgs, double lngwgs, out double latmars, out double lngmars) { double num = lngwgs; double num2 = latwgs; for (long num3 = 0L; num3 < 10; num3++) { if (num < 72.0 || num > 137.9 || num2 < 10.0 || num2 > 54.9) { latmars = latwgs; lngmars = lngwgs; return false; } int num4 = (int)Math.Floor((num - 72.0) * 10.0); int num5 = (int)Math.Floor((num2 - 10.0) * 10.0); double num6 = Lx[ID(num4, num5)]; double num7 = Ly[ID(num4, num5)]; double num8 = Lx[ID(num4 + 1, num5)]; double num9 = Ly[ID(num4 + 1, num5)]; double num10 = Lx[ID(num4 + 1, num5 + 1)]; double num11 = Ly[ID(num4 + 1, num5 + 1)]; double num12 = Lx[ID(num4, num5 + 1)]; double num13 = Ly[ID(num4, num5 + 1)]; double num14 = (num - 72.0 - 0.1 * (double)num4) * 10.0; double num15 = (num2 - 10.0 - 0.1 * (double)num5) * 10.0; double num16 = (1.0 - num14) * (1.0 - num15) * num6 + num14 * (1.0 - num15) * num8 + num14 * num15 * num10 + (1.0 - num14) * num15 * num12 - num; double num17 = (1.0 - num14) * (1.0 - num15) * num7 + num14 * (1.0 - num15) * num9 + num14 * num15 * num11 + (1.0 - num14) * num15 * num13 - num2; num = (num + lngwgs + num16) / 2.0; num2 = (num2 + latwgs + num17) / 2.0; } lngmars = Math.Round(num, 6); latmars = Math.Round(num2, 6); return true; } public bool Mars2Wgs(double latmars, double lngmars, out double latwgs, out double lngwgs) { double num = lngmars; double num2 = latmars; for (long num3 = 0L; num3 < 10; num3++) { if (num < 72.0 || num > 137.9 || num2 < 10.0 || num2 > 54.9) { latwgs = latmars; lngwgs = lngmars; return false; } int num4 = (int)Math.Floor((num - 72.0) * 10.0); int num5 = (int)Math.Floor((num2 - 10.0) * 10.0); double num6 = Lx[ID(num4, num5)]; double num7 = Ly[ID(num4, num5)]; double num8 = Lx[ID(num4 + 1, num5)]; double num9 = Ly[ID(num4 + 1, num5)]; double num10 = Lx[ID(num4 + 1, num5 + 1)]; double num11 = Ly[ID(num4 + 1, num5 + 1)]; double num12 = Lx[ID(num4, num5 + 1)]; double num13 = Ly[ID(num4, num5 + 1)]; double num14 = (num - 72.0 - 0.1 * (double)num4) * 10.0; double num15 = (num2 - 10.0 - 0.1 * (double)num5) * 10.0; double num16 = (1.0 - num14) * (1.0 - num15) * num6 + num14 * (1.0 - num15) * num8 + num14 * num15 * num10 + (1.0 - num14) * num15 * num12 - num; double num17 = (1.0 - num14) * (1.0 - num15) * num7 + num14 * (1.0 - num15) * num9 + num14 * num15 * num11 + (1.0 - num14) * num15 * num13 - num2; num = (num + lngmars - num16) / 2.0; num2 = (num2 + latmars - num17) / 2.0; } lngwgs = Math.Round(num, 6); latwgs = Math.Round(num2, 6); return true; } }
参考文档:https://github.com/shenqiliang/WGS2Mars
GPS.CoordinatesTransformation下载地址:GPS.CoordinatesTransformation.txt
标签:num4,num5,WGS84,double,num14,num,num15,互转,GPS 来源: https://www.cnblogs.com/lonelyxmas/p/11773769.html