internal static LatLng OsRefToAiry1830LatLng(OsRef osref)
        {
            // This is deliberately ugly C#. It's ported from javascript at http://www.jstott.me.uk/jscoord/ (v1.1.1)
            // The less I touch it, the less chance there is of breaking it.

            var OSGB_F0  = 0.9996012717;
            var N0       = -100000.0;
            var E0       = 400000.0;
            var phi0     = DegreesToRadians(49.0);
            var lambda0  = DegreesToRadians(-2.0);
            var a        = Ellipsoid.Airy1830.a;
            var b        = Ellipsoid.Airy1830.b;
            var eSquared = Ellipsoid.Airy1830.eSquared;
            var phi      = 0.0;
            var lambda   = 0.0;
            var E        = osref.Easting;
            var N        = osref.Northing;
            var n        = (a - b) / (a + b);
            var M        = 0.0;
            var phiPrime = ((N - N0) / (a * OSGB_F0)) + phi0;

            do
            {
                M =
                    (b * OSGB_F0)
                    * (((1 + n + ((5.0 / 4.0) * n * n) + ((5.0 / 4.0) * n * n * n))
                        * (phiPrime - phi0))
                       - (((3 * n) + (3 * n * n) + ((21.0 / 8.0) * n * n * n))
                          * Math.Sin(phiPrime - phi0)
                          * Math.Cos(phiPrime + phi0))
                       + ((((15.0 / 8.0) * n * n) + ((15.0 / 8.0) * n * n * n))
                          * Math.Sin(2.0 * (phiPrime - phi0))
                          * Math.Cos(2.0 * (phiPrime + phi0)))
                       - (((35.0 / 24.0) * n * n * n)
                          * Math.Sin(3.0 * (phiPrime - phi0))
                          * Math.Cos(3.0 * (phiPrime + phi0))));
                phiPrime += (N - N0 - M) / (a * OSGB_F0);
            } while ((N - N0 - M) >= 0.001);
            var v   = a * OSGB_F0 * Math.Pow(1.0 - eSquared * SinSquared(phiPrime), -0.5);
            var rho =
                a
                * OSGB_F0
                * (1.0 - eSquared)
                * Math.Pow(1.0 - eSquared * SinSquared(phiPrime), -1.5);
            var etaSquared = (v / rho) - 1.0;
            var VII        = Math.Tan(phiPrime) / (2 * rho * v);
            var VIII       =
                (Math.Tan(phiPrime) / (24.0 * rho * Math.Pow(v, 3.0)))
                * (5.0
                   + (3.0 * TanSquared(phiPrime))
                   + etaSquared
                   - (9.0 * TanSquared(phiPrime) * etaSquared));
            var IX =
                (Math.Tan(phiPrime) / (720.0 * rho * Math.Pow(v, 5.0)))
                * (61.0
                   + (90.0 * TanSquared(phiPrime))
                   + (45.0 * TanSquared(phiPrime) * TanSquared(phiPrime)));
            var X  = Sec(phiPrime) / v;
            var XI =
                (Sec(phiPrime) / (6.0 * v * v * v))
                * ((v / rho) + (2 * TanSquared(phiPrime)));
            var XII =
                (Sec(phiPrime) / (120.0 * Math.Pow(v, 5.0)))
                * (5.0
                   + (28.0 * TanSquared(phiPrime))
                   + (24.0 * TanSquared(phiPrime) * TanSquared(phiPrime)));
            var XIIA =
                (Sec(phiPrime) / (5040.0 * Math.Pow(v, 7.0)))
                * (61.0
                   + (662.0 * TanSquared(phiPrime))
                   + (1320.0 * TanSquared(phiPrime) * TanSquared(phiPrime))
                   + (720.0
                      * TanSquared(phiPrime)
                      * TanSquared(phiPrime)
                      * TanSquared(phiPrime)));

            phi =
                phiPrime
                - (VII * Math.Pow(E - E0, 2.0))
                + (VIII * Math.Pow(E - E0, 4.0))
                - (IX * Math.Pow(E - E0, 6.0));
            lambda =
                lambda0
                + (X * (E - E0))
                - (XI * Math.Pow(E - E0, 3.0))
                + (XII * Math.Pow(E - E0, 5.0))
                - (XIIA * Math.Pow(E - E0, 7.0));

            return(new LatLng(RadiansToDegrees(phi), RadiansToDegrees(lambda)));
        }
Пример #2
0
 public double DistanceInMetresFrom(OsRef start)
 {
     return(Math.Pow(Math.Pow((double)_northing - start.Northing, 2.0) + Math.Pow((double)_easting - start.Easting, 2.0), 0.5));
 }
        // We include these here as internal methods to keep all the ported javascript trigonometry in one class.
        // They are exposed as public methods of OsRef.
        internal static LatLng OsRefToWGS84LatLng(OsRef osref)
        {
            LatLng airy1830 = OsRefToAiry1830LatLng(osref);

            return(airy1830.ToWGS84());
        }