Esempio n. 1
0
        /// <summary>
        /// Convert this latitude and longitude into an OSGB (Ordnance Survey of Great
        /// Britain) grid reference.
        /// </summary>
        /// <param name="ll">The latitude and longitude.</param>
        /// <exception cref="ArgumentException">If the northing or easting are out of range</exception>
        public OSRef(LatLng ll) : base(OSGB36Datum.Instance)
        {
            ll.ToDatum(OSGB36Datum.Instance);

            Airy1830Ellipsoid airy1830 = Airy1830Ellipsoid.Instance;
            double            OSGB_F0  = 0.9996012717;
            double            N0       = -100000.0;
            double            E0       = 400000.0;
            double            phi0     = Util.ToRadians(49.0);
            double            lambda0  = Util.ToRadians(-2.0);
            double            a        = airy1830.SemiMajorAxis;
            double            b        = airy1830.SemiMinorAxis;
            double            eSquared = airy1830.EccentricitySquared;
            double            phi      = Util.ToRadians(ll.Latitude);
            double            lambda   = Util.ToRadians(ll.Longitude);
            double            E        = 0.0;
            double            N        = 0.0;
            double            n        = (a - b) / (a + b);
            double            v        = a * OSGB_F0
                                         * Math.Pow(1.0 - eSquared * Util.sinSquared(phi), -0.5);
            double rho = a * OSGB_F0 * (1.0 - eSquared)
                         * Math.Pow(1.0 - eSquared * Util.sinSquared(phi), -1.5);
            double etaSquared = (v / rho) - 1.0;
            double M          = (b * OSGB_F0)
                                * (((1 + n + ((5.0 / 4.0) * n * n) + ((5.0 / 4.0) * n * n * n)) * (phi - phi0))
                                   - (((3 * n) + (3 * n * n) + ((21.0 / 8.0) * n * n * n))
                                      * Math.Sin(phi - phi0) * Math.Cos(phi + phi0))
                                   + ((((15.0 / 8.0) * n * n) + ((15.0 / 8.0) * n * n * n))
                                      * Math.Sin(2.0 * (phi - phi0)) * Math.Cos(2.0 * (phi + phi0))) - (((35.0 / 24.0)
                                                                                                         * n * n * n)
                                                                                                        * Math.Sin(3.0 * (phi - phi0)) * Math.Cos(3.0 * (phi + phi0))));
            double I   = M + N0;
            double II  = (v / 2.0) * Math.Sin(phi) * Math.Cos(phi);
            double III = (v / 24.0) * Math.Sin(phi) * Math.Pow(Math.Cos(phi), 3.0)
                         * (5.0 - Util.tanSquared(phi) + (9.0 * etaSquared));
            double IIIA = (v / 720.0) * Math.Sin(phi) * Math.Pow(Math.Cos(phi), 5.0)
                          * (61.0 - (58.0 * Util.tanSquared(phi)) + Math.Pow(Math.Tan(phi), 4.0));
            double IV = v * Math.Cos(phi);
            double V  = (v / 6.0) * Math.Pow(Math.Cos(phi), 3.0)
                        * ((v / rho) - Util.tanSquared(phi));
            double VI = (v / 120.0)
                        * Math.Pow(Math.Cos(phi), 5.0)
                        * (5.0 - (18.0 * Util.tanSquared(phi)) + (Math.Pow(Math.Tan(phi), 4.0))
                           + (14 * etaSquared) - (58 * Util.tanSquared(phi) * etaSquared));

            N = I + (II * Math.Pow(lambda - lambda0, 2.0))
                + (III * Math.Pow(lambda - lambda0, 4.0))
                + (IIIA * Math.Pow(lambda - lambda0, 6.0));
            E = E0 + (IV * (lambda - lambda0)) + (V * Math.Pow(lambda - lambda0, 3.0))
                + (VI * Math.Pow(lambda - lambda0, 5.0));

            Easting  = E;
            Northing = N;
        }
Esempio n. 2
0
        /// <summary>
        /// Convert this latitude and longitude into an OSGB (Ordnance Survey of Great
        /// Britain) grid reference.
        /// </summary>
        /// <param name="ll">The latitude and longitude.</param>
        /// <exception cref="ArgumentException">If the northing or easting are out of range</exception>
        public OSRef(LatLng ll) : base(OSGB36Datum.Instance)
        {
            ll.ToDatum(OSGB36Datum.Instance);

            Airy1830Ellipsoid airy1830 = Airy1830Ellipsoid.Instance;
            const double      osgbF0   = 0.9996012717;
            const double      n0       = -100000.0;
            const double      e0       = 400000.0;
            double            phi0     = Util.ToRadians(49.0);
            double            lambda0  = Util.ToRadians(-2.0);
            double            a        = airy1830.SemiMajorAxis;
            double            b        = airy1830.SemiMinorAxis;
            double            eSquared = airy1830.EccentricitySquared;
            double            phi      = Util.ToRadians(ll.Latitude);
            double            lambda   = Util.ToRadians(ll.Longitude);
            double            n        = (a - b) / (a + b);
            double            v        = a * osgbF0
                                         * Math.Pow(1.0 - eSquared * Util.SinSquared(phi), -0.5);
            double rho = a * osgbF0 * (1.0 - eSquared)
                         * Math.Pow(1.0 - eSquared * Util.SinSquared(phi), -1.5);
            double etaSquared = (v / rho) - 1.0;
            double m          = (b * osgbF0)
                                * (((1 + n + ((5.0 / 4.0) * n * n) + ((5.0 / 4.0) * n * n * n)) * (phi - phi0))
                                   - (((3 * n) + (3 * n * n) + ((21.0 / 8.0) * n * n * n))
                                      * Math.Sin(phi - phi0) * Math.Cos(phi + phi0))
                                   + ((((15.0 / 8.0) * n * n) + ((15.0 / 8.0) * n * n * n))
                                      * Math.Sin(2.0 * (phi - phi0)) * Math.Cos(2.0 * (phi + phi0))) - (((35.0 / 24.0)
                                                                                                         * n * n * n)
                                                                                                        * Math.Sin(3.0 * (phi - phi0)) * Math.Cos(3.0 * (phi + phi0))));
            double I   = m + n0;
            double ii  = (v / 2.0) * Math.Sin(phi) * Math.Cos(phi);
            double iii = (v / 24.0) * Math.Sin(phi) * Math.Pow(Math.Cos(phi), 3.0)
                         * (5.0 - Util.TanSquared(phi) + (9.0 * etaSquared));
            double iiia = (v / 720.0) * Math.Sin(phi) * Math.Pow(Math.Cos(phi), 5.0)
                          * (61.0 - (58.0 * Util.TanSquared(phi)) + Math.Pow(Math.Tan(phi), 4.0));
            double iv = v * Math.Cos(phi);
            double V  = (v / 6.0) * Math.Pow(Math.Cos(phi), 3.0)
                        * ((v / rho) - Util.TanSquared(phi));
            double vi = (v / 120.0)
                        * Math.Pow(Math.Cos(phi), 5.0)
                        * (5.0 - (18.0 * Util.TanSquared(phi)) + (Math.Pow(Math.Tan(phi), 4.0))
                           + (14 * etaSquared) - (58 * Util.TanSquared(phi) * etaSquared));

            double N = I + (ii * Math.Pow(lambda - lambda0, 2.0))
                       + (iii * Math.Pow(lambda - lambda0, 4.0))
                       + (iiia * Math.Pow(lambda - lambda0, 6.0));
            double e = e0 + (iv * (lambda - lambda0)) + (V * Math.Pow(lambda - lambda0, 3.0))
                       + (vi * Math.Pow(lambda - lambda0, 5.0));

            Easting  = e;
            Northing = N;
        }