示例#1
0
        /// <summary><para>Die Funktion wandelt militärische MGRS-Koordinaten (Military Grid Reference System, UTMREF) in UTM-Koordinaten um.
        /// <para>Die Funktion ist nur für interne Berechnungen bestimmt.</para></para></summary>
        /// <remarks><para>
        /// Hintergründe zum Problem der Koordinatentransformationen sowie entsprechende  mathematische
        /// Formeln können den einschlägigen Fachbüchern oder dem Internet entnommen werden.<p />
        /// Quellen:
        /// Bundesamt für Kartographie und Geodäsie<br />
        /// <a href="http://www.bkg.bund.de" target="_blank">http://www.bkg.bund.de</a><br />
        /// <a href="http://crs.bkg.bund.de" target="_blank">http://crs.bkg.bund.de</a><br />
        /// </para></remarks>
        ///
        /// <param name="mgrs">Ein <see cref="MGRS"/>-Objekt.</param>
        /// <returns>Ein <see cref="UTM"/>-Objekt.</returns>
        internal UTM MGRUTM(MGRS mgrs)
        {
            int    zone      = mgrs.Zone;
            string eastgrid  = mgrs.Grid.Substring(0, 1);
            string northgrid = mgrs.Grid.Substring(1, 1);

            // Führende Stelle East-Koordinate aus Planquadrat(east) und Koordinaten berechnen
            int i           = mgrs.Zone % 3;
            int stellenwert = 0;

            if (i == 0)
            {
                stellenwert = MGRS_EAST0.IndexOf(eastgrid) + 1;
            }
            if (i == 1)
            {
                stellenwert = MGRS_EAST1.IndexOf(eastgrid) + 1;
            }
            if (i == 2)
            {
                stellenwert = MGRS_EAST2.IndexOf(eastgrid) + 1;
            }
            string sEast = stellenwert.ToString() + mgrs.EastString.PadRight(5, '0');

            // Führende Stelle North-Koordinate aus Planquadrat(north)
            i           = mgrs.Zone % 2;
            stellenwert = 0;
            if (i == 0)
            {
                stellenwert = MGRS_NORTH0.IndexOf(northgrid);
            }
            else
            {
                stellenwert = MGRS_NORTH1.IndexOf(northgrid);
            }

            // Führende Stelle North-Koordinate berechnen
            char band = mgrs.Band.ToCharArray()[0];

            if (zone < MIN_ZONE || zone > MAX_ZONE || band < MIN_BAND || band > MAX_BAND)
            {
                throw new ErrorProvider.GeoException(new ErrorProvider.ErrorMessage("ERROR_UTM_ZONE"));
            }

            if (band >= 'N')
            {
                if ((band == 'Q') && (stellenwert < 10))
                {
                    stellenwert += 20;
                }
                if (band >= 'R')
                {
                    stellenwert += 20;
                }
                if ((band == 'S') && (stellenwert < 30))
                {
                    stellenwert += 20;
                }
                if (band >= 'T')
                {
                    stellenwert += 20;
                }
                if ((band == 'U') && (stellenwert < 50))
                {
                    stellenwert += 20;
                }
                if (band >= 'V')
                {
                    stellenwert += 20;
                }
                if ((band == 'W') && (stellenwert < 70))
                {
                    stellenwert += 20;
                }
                if (band >= 'X')
                {
                    stellenwert += 20;
                }
            }
            else
            {
                if ((band == 'C') && (stellenwert < 10))
                {
                    stellenwert += 20;
                }
                if (band >= 'D')
                {
                    stellenwert += 20;
                }
                if ((band == 'F') && (stellenwert < 30))
                {
                    stellenwert += 20;
                }
                if (band >= 'G')
                {
                    stellenwert += 20;
                }
                if ((band == 'H') && (stellenwert < 50))
                {
                    stellenwert += 20;
                }
                if (band >= 'J')
                {
                    stellenwert += 20;
                }
                if ((band == 'K') && (stellenwert < 70))
                {
                    stellenwert += 20;
                }
                if (band >= 'L')
                {
                    stellenwert += 20;
                }
            }

            // North-Koordinate
            string sNorth = "";

            if ((stellenwert.ToString()).Length == 1)
            {
                sNorth = "0";
            }
            sNorth += stellenwert.ToString() + mgrs.NorthString.PadRight(5, '0');

            return(new UTM(zone, band.ToString(), double.Parse(sEast), double.Parse(sNorth)));
        }
示例#2
0
        /// <summary><para>Die Funktion wandelt zivile UTM Koordinaten in militärische Koordinaten um.
        /// <para>Die Funktion ist nur für interne Berechnungen bestimmt.</para></para></summary>
        /// <remarks><para>
        /// Hintergründe zum Problem der Koordinatentransformationen sowie entsprechende  mathematische
        /// Formeln können den einschlägigen Fachbüchern oder dem Internet entnommen werden.<p />
        /// Quellen:
        /// Bundesamt für Kartographie und Geodäsie<br />
        /// <a href="http://www.bkg.bund.de" target="_blank">http://www.bkg.bund.de</a><br />
        /// <a href="http://crs.bkg.bund.de" target="_blank">http://crs.bkg.bund.de</a><br />
        /// </para></remarks>
        ///
        /// <param name="utm">Ein <see cref="GeoUtility.GeoSystem.UTM"/>-Objekt.</param>
        /// <returns>Ein <see cref="GeoUtility.GeoSystem.MGRS"/>-Objekt (UTMREF/MGRS).</returns>
        internal MGRS UTMMGR(UTM utm)
        {
            int    zone = utm.Zone;
            string band = utm.Band;
            char   cz2  = band.ToCharArray()[0];

            char[] sep = { ',', '.' };

            // Die höchsten Stellen der East und North Koordinate werden für die Berechnung des Planquadrates benötigt.
            string e          = utm.EastString.Split(sep)[0];
            int    east_plan  = int.Parse(e.Substring(0, 1)); // 1. Stelle des Ostwertes
            string n          = utm.NorthString.Split(sep)[0];
            int    north_plan = int.Parse(n.Substring(0, 2)); // 1. und 2. Stelle des Nordwertes

            // East Koordinate
            string east = ((int)Math.Round(utm.East)).ToString();

            if (east.Length > 2)
            {
                east = east.Remove(0, 1);
            }

            // North Koordinate
            string north = ((int)Math.Round(utm.North)).ToString();

            if (north.Length > 2)
            {
                north = north.Remove(0, 2);
            }

            // Anzahl Stellen bei East und North müssen gleich sein
            if (east.Length < north.Length)
            {
                east = east.PadLeft(north.Length, '0');
            }
            else if (north.Length < east.Length)
            {
                north = north.PadLeft(east.Length, '0');
            }

            if (zone < MIN_ZONE || zone > MAX_ZONE || cz2 < MIN_BAND || cz2 > MAX_BAND)
            {
                throw new ErrorProvider.GeoException(new ErrorProvider.ErrorMessage("ERROR_UTM_ZONE"));
            }

            // Berechnung des Indexes für die Ost-Planquadrat Komponente
            int eastgrid = 0;
            int i        = zone % 3;

            if (i == 1)
            {
                eastgrid = east_plan - 1;
            }
            if (i == 2)
            {
                eastgrid = east_plan + 7;
            }
            if (i == 0)
            {
                eastgrid = east_plan + 15;
            }

            // Berechnung des Indexes für die Nord-Planquadrat Komponente
            int northgrid = 0;

            i = zone % 2;
            if (i != 1)
            {
                northgrid = 5;
            }
            i = north_plan;
            while (i - 20 >= 0)
            {
                i = i - 20;
            }
            northgrid += i;
            if (northgrid > 19)
            {
                northgrid = northgrid - 20;
            }

            // Planquadrat aus den vorher berechneten Indizes zusammensetzen
            string plan = MGRS_EAST.Substring(eastgrid, 1) + MGRS_NORTH1.Substring(northgrid, 1);

            return(new MGRS(utm.Zone, utm.Band, plan, double.Parse(east), double.Parse(north)));
        }