public GeoCoordinate ConvertToWGS84(double x, double y)
        {
            double d1            = System.Math.Pow(System.Math.Sqrt(System.Math.Pow(x - this._x_origin, 2.0) + System.Math.Pow(this._r_0 - (y - this._y_origin), 2.0)) / (this._ellipsoid.SemiMajorAxis * this._g), 1.0 / this._n);
            double num1          = System.Math.Atan((x - this._x_origin) / (this._r_0 - (y - this._y_origin))) / this._n + this._longitude_origin_radians;
            double a             = System.Math.PI / 2.0 - 2.0 * System.Math.Atan(d1);
            double eccentricity1 = this._ellipsoid.Eccentricity;

            for (double num2 = 0.0; num2 != a; a = System.Math.PI / 2.0 - 2.0 * System.Math.Atan(d1 * System.Math.Pow((1.0 - eccentricity1 * System.Math.Sin(a)) / (1.0 + eccentricity1 * System.Math.Sin(a)), eccentricity1 / 2.0)))
            {
                num2 = a;
            }
            Hayford1924Ellipsoid hayford1924Ellipsoid = new Hayford1924Ellipsoid();
            double           num3             = a;
            double           num4             = num1;
            double           num5             = 100.0;
            double           semiMajorAxis1   = hayford1924Ellipsoid.SemiMajorAxis;
            double           eccentricity2    = hayford1924Ellipsoid.Eccentricity;
            double           num6             = eccentricity2 * eccentricity2;
            double           num7             = System.Math.Sin(num3);
            double           num8             = System.Math.Cos(num3);
            double           num9             = System.Math.Sin(num4);
            double           num10            = System.Math.Cos(num4);
            double           num11            = semiMajorAxis1 / System.Math.Sqrt(1.0 - num6 * num7 * num7);
            double           num12            = (num11 + num5) * num8 * num10;
            double           num13            = (num11 + num5) * num8 * num9;
            double           num14            = ((1.0 - num6) * num11 + num5) * num7;
            double           num15            = 106.868628;
            double           num16            = 52.297783;
            double           num17            = 103.723893;
            double           num18            = num12 - num15;
            double           num19            = num13 + num16;
            double           num20            = num17;
            double           num21            = num14 - num20;
            double           num22            = new Degree(9.34916666666667E-05).Value;
            double           num23            = System.Math.Sin(num22);
            double           num24            = System.Math.Cos(num22);
            double           num25            = new Degree(-0.000126931944444444).Value;
            double           num26            = System.Math.Sin(num25);
            double           num27            = System.Math.Cos(num25);
            double           num28            = new Degree(0.0005117175).Value;
            double           num29            = System.Math.Sin(num28);
            double           num30            = System.Math.Cos(num28);
            double           num31            = num19 * num24 - num21 * num23;
            double           num32            = num31 * num23 + num21 * num24;
            double           num33            = num18 * num27 + num32 * num26;
            double           num34            = num33 * -num26 + num32 * num27;
            double           num35            = num33 * num30 - num31 * num29;
            double           num36            = num35 * num29 + num31 * num30;
            Wgs1984Ellipsoid wgs1984Ellipsoid = new Wgs1984Ellipsoid();
            double           eccentricity3    = wgs1984Ellipsoid.Eccentricity;
            double           num37            = eccentricity3 * eccentricity3;
            double           d2             = num35 * num35 + num36 * num36;
            double           num38          = System.Math.Sqrt(d2);
            double           num39          = num34 * num34;
            double           num40          = System.Math.Sqrt(d2 + num39);
            double           flattening     = wgs1984Ellipsoid.Flattening;
            double           semiMajorAxis2 = wgs1984Ellipsoid.SemiMajorAxis;
            double           num41          = System.Math.Atan(num34 / num38 * (1.0 - flattening + num37 * semiMajorAxis2 / num40));
            double           num42          = System.Math.Atan(num36 / num35);

            return(new GeoCoordinate(new Radian(System.Math.Atan((num34 * (1.0 - flattening) + num37 * semiMajorAxis2 * System.Math.Pow(System.Math.Sin(num41), 3.0)) / ((1.0 - flattening) * (num38 - num37 * semiMajorAxis2 * System.Math.Pow(System.Math.Cos(num41), 3.0))))).Value,
                                     new Radian(num42).Value));
        }
        /// <summary>
        /// Converts the given lambert coordinates to mercator coordinates.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public GeoCoordinate ConvertToWGS84(double x, double y)
        {
            double latitude;
            double longitude;

            double r = (System.Math.Sqrt(
                            System.Math.Pow(x - _x_origin, 2.0) +
                            System.Math.Pow((_r_0 - (y - _y_origin)), 2.0))
                        );

            double t = System.Math.Pow((r / (_ellipsoid.SemiMajorAxis * _g)), 1.0 / _n);

            double phi = System.Math.Atan((x - _x_origin) /
                                          (_r_0 - (y - _y_origin)));

            longitude = ((phi / _n) + _longitude_origin_radians);

            latitude = (System.Math.PI / 2.0 - 2.0 * System.Math.Atan(t));

            double e = _ellipsoid.Eccentricity;

            double new_latitude = 0;

            while (new_latitude != latitude)
            { // iterate 100 times.
                new_latitude = latitude;
                latitude     = (System.Math.PI / 2.0 - 2.0 *
                                System.Math.Atan(t *
                                                 System.Math.Pow(
                                                     ((1.0 - e * System.Math.Sin(latitude)) / (1.0 + e * System.Math.Sin(latitude))),
                                                     e / 2.0)));
            }



            Hayford1924Ellipsoid hayford = new Hayford1924Ellipsoid();

            double phi_72    = latitude;  // phi = latitude!
            double lambda_72 = longitude; // lambda = longitude!
            double h_72      = 100;

            double a_72          = hayford.SemiMajorAxis;
            double e_72          = hayford.Eccentricity;
            double es_72         = e_72 * e_72;
            double sin_phi_72    = System.Math.Sin(phi_72);
            double cos_phi_72    = System.Math.Cos(phi_72);
            double sin_lambda_72 = System.Math.Sin(lambda_72);
            double cos_lambda_72 = System.Math.Cos(lambda_72);
            double v_72          = a_72 / System.Math.Sqrt(1 - (es_72 * sin_phi_72 * sin_phi_72));

            double X_72 = (v_72 + h_72) * cos_phi_72 * cos_lambda_72;
            double Y_72 = (v_72 + h_72) * cos_phi_72 * sin_lambda_72;
            double Z_72 = ((1 - es_72) * v_72 + h_72) * sin_phi_72;

            // ALL OK

            //X_72 = X_72 * (1 / 1.0000012747);
            //Y_72 = Y_72 * (1 / 1.0000012747);
            //Z_72 = Z_72 * (1 / 1.0000012747);

            // translations.
            double x_trans = 106.868628;
            double y_trans = 52.297783;
            double z_trans = 103.723893;

            double X_89 = X_72 - x_trans;
            double Y_89 = Y_72 + y_trans;
            double Z_89 = Z_72 - z_trans;

            // rotations.
            double x_angle     = ((Radian) new Degree(0.336570 / 3600)).Value;
            double sin_x_angle = System.Math.Sin(x_angle);
            double cos_x_angle = System.Math.Cos(x_angle);
            double y_angle     = ((Radian) new Degree(-0.456955 / 3600)).Value;
            double sin_y_angle = System.Math.Sin(y_angle);
            double cos_y_angle = System.Math.Cos(y_angle);
            double z_angle     = ((Radian) new Degree(1.842183 / 3600)).Value;
            double sin_z_angle = System.Math.Sin(z_angle);
            double cos_z_angle = System.Math.Cos(z_angle);

            // rotate around x.
            //X_89 = X_89;
            Y_89 = Y_89 * cos_x_angle - Z_89 * sin_x_angle;
            Z_89 = Y_89 * sin_x_angle + Z_89 * cos_x_angle;
            // rotate around y.
            X_89 = X_89 * cos_y_angle + Z_89 * sin_y_angle;
            //Y_89 = Y_89;
            Z_89 = X_89 * (-sin_y_angle) + Z_89 * cos_y_angle;
            // rotate around Z.
            X_89 = X_89 * cos_z_angle - Y_89 * sin_z_angle;
            Y_89 = X_89 * sin_z_angle + Y_89 * cos_z_angle;
            //Z_89 = Z_89;

            Wgs1984Ellipsoid wgs1984 = new Wgs1984Ellipsoid();

            e = wgs1984.Eccentricity;
            double es = e * e;
            double ps = X_89 * X_89 + Y_89 * Y_89;
            double p  = System.Math.Sqrt(ps);

            r = System.Math.Sqrt(ps + Z_89 * Z_89);

            double f = wgs1984.Flattening;
            double a = wgs1984.SemiMajorAxis;

            double u      = System.Math.Atan((Z_89 / p) * ((1 - f) + (es * a / r)));
            double lambda = System.Math.Atan(Y_89 / X_89);

            phi = System.Math.Atan((Z_89 * (1 - f) + (es * a * System.Math.Pow(System.Math.Sin(u), 3)))
                                   /
                                   ((1 - f) * (p - (es * a * System.Math.Pow(System.Math.Cos(u), 3)))));

            Degree longitude_84 = new Radian(lambda);
            Degree latitude_84  = new Radian(phi);

            return(new GeoCoordinate(latitude_84.Value, longitude_84.Value));
        }