Exemplo n.º 1
0
        private void ParseRegTopp(string regToppLine)
        {
            if(regToppLine.Length != RegTopLineLength)
            {
                throw new RegTopParseException(
                    "Invalid line length. Was " + regToppLine.Length + " expected " + RegTopLineLength);
            }

            StopNumber = regToppLine.Substring(StopNrStart, StopNrLength).Substring(4,4).Trim();
            StopName = StopNumber + " " + regToppLine.Substring(StopNameStart, StopNameLength).Trim();
            XCoord = regToppLine.Substring(XCoordStart, XCoordLength).Trim();
            YCoord = regToppLine.Substring(YCoordStart, YCoordLength).Trim();

            var utmX = double.Parse(XCoord);
            var utmY = double.Parse(YCoord);
            var utmCoordinate = new CartesianCoordinate(utmX, utmY);

            LatLon = new CoordinateConverter().UtmXyToLatLon(utmCoordinate, 32, false);
        }
Exemplo n.º 2
0
        /*
        * MapXYToLatLon
        *
        * Converts x and y coordinates in the Transverse Mercator projection to
        * a latitude/longitude pair.  Note that Transverse Mercator is not
        * the same as UTM; a scale factor is required to convert between them.
        *
        * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
        *   GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
        *
        * Inputs:
        *   x - The easting of the point, in meters.
        *   y - The northing of the point, in meters.
        *   lambda0 - Longitude of the central meridian to be used, in radians.
        *
        * Outputs:
        *   philambda - A 2-element containing the latitude and longitude
        *               in radians.
        *
        * Returns:
        *   The public double does not return a value.
        *
        * Remarks:
        *   The local variables Nf, nuf2, tf, and tf2 serve the same purpose as
        *   N, nu2, t, and t2 in MapLatLonToXY, but they are computed with respect
        *   to the footpoint latitude phif.
        *
        *   x1frac, x2frac, x2poly, x3poly, etc. are to enhance readability and
        *   to optimize computations.
        *
        */
        public GeographicCoordinate MapXyToLatLon(CartesianCoordinate xy, double lambda0)
        {
            /* Get the value of phif, the footpoint latitude. */
            var phif = FootpointLatitude(xy.Y);

            /* Precalculate ep2 */
            var ep2 = (Math.Pow(sm_a, 2.0) - Math.Pow(sm_b, 2.0)) / Math.Pow(sm_b, 2.0);

            /* Precalculate cos (phif) */
            var cf = Math.Cos(phif);

            /* Precalculate nuf2 */
            var nuf2 = ep2 * Math.Pow(cf, 2.0);

            /* Precalculate Nf and initialize Nfpow */
            var Nf = Math.Pow(sm_a, 2.0) / (sm_b * Math.Sqrt(1 + nuf2));
            var Nfpow = Nf;

            /* Precalculate tf */
            var tf = Math.Tan(phif);
            var tf2 = tf * tf;
            var tf4 = tf2 * tf2;

            /* Precalculate fractional coefficients for x**n in the equations
               below to simplify the expressions for latitude and longitude. */
            var x1frac = 1.0 / (Nfpow * cf);

            Nfpow *= Nf;   /* now equals Nf**2) */
            var x2frac = tf / (2.0 * Nfpow);

            Nfpow *= Nf;   /* now equals Nf**3) */
            var x3frac = 1.0 / (6.0 * Nfpow * cf);

            Nfpow *= Nf;   /* now equals Nf**4) */
            var x4frac = tf / (24.0 * Nfpow);

            Nfpow *= Nf;   /* now equals Nf**5) */
            var x5frac = 1.0 / (120.0 * Nfpow * cf);

            Nfpow *= Nf;   /* now equals Nf**6) */
            var x6frac = tf / (720.0 * Nfpow);

            Nfpow *= Nf;   /* now equals Nf**7) */
            var x7frac = 1.0 / (5040.0 * Nfpow * cf);

            Nfpow *= Nf;   /* now equals Nf**8) */
            var x8frac = tf / (40320.0 * Nfpow);

            /* Precalculate polynomial coefficients for x**n.
               -- x**1 does not have a polynomial coefficient. */
            var x2poly = -1.0 - nuf2;

            var x3poly = -1.0 - 2 * tf2 - nuf2;

            var x4poly = 5.0 + 3.0 * tf2 + 6.0 * nuf2 - 6.0 * tf2 * nuf2
                - 3.0 * (nuf2 * nuf2) - 9.0 * tf2 * (nuf2 * nuf2);

            var x5poly = 5.0 + 28.0 * tf2 + 24.0 * tf4 + 6.0 * nuf2 + 8.0 * tf2 * nuf2;

            var x6poly = -61.0 - 90.0 * tf2 - 45.0 * tf4 - 107.0 * nuf2 + 162.0 * tf2 * nuf2;

            var x7poly = -61.0 - 662.0 * tf2 - 1320.0 * tf4 - 720.0 * (tf4 * tf2);

            var x8poly = 1385.0 + 3633.0 * tf2 + 4095.0 * tf4 + 1575 * (tf4 * tf2);

            /* Calculate latitude */
            var lat = phif + x2frac * x2poly * (xy.X * xy.X)
               + x4frac * x4poly * Math.Pow(xy.X, 4.0)
               + x6frac * x6poly * Math.Pow(xy.X, 6.0)
               + x8frac * x8poly * Math.Pow(xy.X, 8.0);

            /* Calculate longitude */
            var lon = lambda0 + x1frac * xy.X
                + x3frac * x3poly * Math.Pow(xy.X, 3.0)
                + x5frac * x5poly * Math.Pow(xy.X, 5.0)
                + x7frac * x7poly * Math.Pow(xy.X, 7.0);

            return new GeographicCoordinate(RadToDeg(lon), RadToDeg(lat));
        }
Exemplo n.º 3
0
        /*
        * UTMXYToLatLon
        *
        * Converts x and y coordinates in the Universal Transverse Mercator
        * projection to a latitude/longitude pair.
        *
        * Inputs:
        *	x - The easting of the point, in meters.
        *	y - The northing of the point, in meters.
        *	zone - The UTM zone in which the point lies.
        *	southhemi - True if the point is in the southern hemisphere;
        *               false otherwise.
        *
        * Outputs:
        *	latlon - A 2-element array containing the latitude and
        *            longitude of the point, in radians.
        *
        * Returns:
        *	The public double does not return a value.
        *
        */
        public GeographicCoordinate UtmXyToLatLon(CartesianCoordinate utm, int zone, bool southhemi)
        {
            utm.X -= 500000.0;
            utm.X /= UTMScaleFactor;

            /* If in southern hemisphere, adjust y accordingly. */
            if (southhemi)
            {
                utm.Y -= 10000000.0;
            }

            utm.Y /= UTMScaleFactor;

            var cmeridian = UtmCentralMeridian(zone);

            return MapXyToLatLon(utm, cmeridian);
        }
Exemplo n.º 4
0
        /*
        * LatLonToUTMXY
        *
        * Converts a latitude/longitude pair to x and y coordinates in the
        * Universal Transverse Mercator projection.
        *
        * Inputs:
        *   lat - Latitude of the point, in radians.
        *   lon - Longitude of the point, in radians.
        *   zone - UTM zone to be used for calculating values for x and y.
        *          If zone is less than 1 or greater than 60, the routine
        *          will determine the appropriate zone from the value of lon.
        *
        * Outputs:
        *   xy - A 2-element array where the UTM x and y values will be stored.
        *
        * Returns:
        *   The UTM zone used for calculating the values of x and y.
        *
        */
        public CartesianCoordinate LatLonToUtmXy(CartesianCoordinate latLon, int zone)
        {
            var coordinate = MapLatLonToXy(latLon.X, latLon.Y, UtmCentralMeridian(zone));

            /* Adjust easting and northing for UTM system. */
            coordinate.X = coordinate.X * UTMScaleFactor + 500000.0;
            coordinate.Y = coordinate.Y * UTMScaleFactor;
            if (coordinate.Y < 0.0)
                coordinate.Y += 10000000.0;

            return coordinate;
        }