GPS positioning offset correction (Mars the WGS84 coordinate system conversion)

Original: the GPS positioning offset correction (Mars the WGS84 coordinate system conversion)

Map coordinate system currently includes:

Earth coordinates (WGS84)

WGS84: World Geodetic System 1984, using a coordinate system is established for the GPS global positioning system.

  • International Standard, taken from the GPS data in the coordinate system of the device
  • Coordinate system used by the international map provider

Mars coordinates (GCJ-02), also known as National Bureau coordinate measuring system

GCJ-02 was developed by the Chinese State Bureau of Surveying and Mapping (folk say Mars coordinate system) GIS coordinate system.
It is a latitude and longitude data of the encryption algorithm, i.e. random deviation added.
Domestic publishing various map systems (including in electronic form), must be at least using GCJ-02 for the first time geographic location of encryption.

  • Chinese standards, positioning obtained from Bank Negara mobile devices using this coordinate system, the coordinate data
  • State regulations: domestic map published by various systems (including in electronic form), must be at least GCJ-02 for the first time geographic location of encryption.

 

Copy the code
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 Download: GPS.CoordinatesTransformation.txt
 
Copy the code

 

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/11773769.html