示例#1
0
        /// <summary><para>Die statische Methode kann dazu verwendet werden, als String-Werte übergebene UTM Parameter
        /// auf ihre Gültigkeit zu überprüfen. Die Methode gibt eine Liste gültiger Parameter, eine Fehlermeldung und
        /// ein <see cref="UTM"/>-Objekt zurück. Ist einer der Parameter ungültig, wird ein <see cref="UTM"/>-Objekt
        /// mir dem Wert null zurückgegeben.</para></summary>
        /// <param name="UTMString">Vollständige UTM-Koordinate als <see cref="System.String"/>-Typ (Bsp.: 32U 312345 4123456 oder 32 U 312345 4123456).</param>
        /// <param name="Utm">Ein gültiges <see cref="UTM"/>-Objekt oder null.</param>
        /// <param name="ErrorMessage">Eine ausführliche Fehlermeldung, falls ein Fehler aufgetreten ist.</param>
        /// <param name="ValidItems">Gibt eine Liste der gültigen bzw. ungültigen Parameter zurück.</param>
        /// <returns>True, wenn der String gültig ist, sonst False.</returns>
        static public bool TryParse(string UTMString, out UTM Utm, out string ErrorMessage, out Dictionary <string, bool> ValidItems)
        {
            Dictionary <string, bool> list = new Dictionary <string, bool>();
            string utmstring = UTMString.Trim();

            char[]   splitter = { ' ' };
            string[] field    = utmstring.Split(splitter);

            if ((field.Length == 3) || (field.Length == 4))
            {
                if (field.Length == 3)
                {
                    if ((field[0].Length == 2) || (field[0].Length == 3))
                    {
                        utmstring = utmstring.Insert(field[0].Length - 1, " ");
                        field     = utmstring.Split(splitter);
                    }
                }
                if (field.Length == 4)
                {
                    return(TryParse(field[0], field[1], field[2], field[3], out Utm, out ErrorMessage, out ValidItems));
                }
            }

            Utm          = null;
            ErrorMessage = new ErrorProvider.ErrorMessage("ERROR_UTM_STRING").Text;
            list.Add("UTMString", false);
            ValidItems = list;
            return(false);
        }
示例#2
0
文件: Comm.cs 项目: wangbo121/UBoat
        public static PointLatLngAlt FromUTM(int zone, double x, double y)
        {
            GeoUtility.GeoSystem.UTM utm = new GeoUtility.GeoSystem.UTM(Math.Abs(zone), x, y, zone < 0 ? GeoUtility.GeoSystem.Base.Geocentric.Hemisphere.South : GeoUtility.GeoSystem.Base.Geocentric.Hemisphere.North);

            PointLatLngAlt ans = ((GeoUtility.GeoSystem.Geographic)utm);

            return(ans);
        }
示例#3
0
        /// <summary>Die Funktion wird aus performancegründen implementiert.</summary>
        /// <param name="obj">Ein beliebiges Objekt.</param>
        /// <returns>Das übergebene Objekt ist gleich oder nicht.</returns>
        public override bool Equals(Object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            UTM utm = (UTM)obj;

            return(this.ToString() == utm.ToString());
        }
示例#4
0
        /// <summary><para>Die generische Methode konvertiert den generischen Typ T in das aktuelle <see cref="UTM"/> Objekt.</para></summary>
        ///
        /// <example>Das Beispiel konvertiert ein bestehendes <see cref="Geographic "/> Objekt in das aktuelle
        /// <see cref="UTM"/> Objekt mit Hilfe der generischen Methode <see cref="ConvertFrom{T}(T)">ConvertFrom&lt;T&gt;(T)</see>:
        /// <code>
        /// using GeoUtility.GeoSystem;
        /// Geographic geo = new Geographic(8.12345, 50.56789);
        /// UTM utm;
        /// utm.ConvertFrom&lt;Geographic&gt;(geo);
        /// </code>
        /// </example>
        ///
        /// <typeparam name="T">Ein aus der Basisklasse <see cref="GeoUtility.GeoSystem.Base.BaseSystem"/> abgeleiteter Typ.</typeparam>
        /// <param name="t">Das zu konvertierende Objekt als generischer Parameter.</param>
        public void ConvertFrom <T>(T t) where T : BaseSystem
        {
            UTM o = null;

            try
            {
                if (typeof(T) == typeof(MGRS))
                {
                    o = (UTM)(MGRS)(BaseSystem)t;
                }
                else if (typeof(T) == typeof(Geographic))
                {
                    o = (UTM)(Geographic)(BaseSystem)t;
                }
                else if (typeof(T) == typeof(GaussKrueger))
                {
                    o = (UTM)(GaussKrueger)(BaseSystem)t;
                }
                else if (typeof(T) == typeof(MapService))
                {
                    o = (UTM)(MapService)(BaseSystem)t;
                }
                if (o != null)
                {
                    this.Zone  = o.Zone;
                    this.Band  = o.Band;
                    this.East  = o.East;
                    this.North = o.North;
                    o          = null;
                }
            }
            catch (Exception ex)
            {
                throw new ErrorProvider.GeoException(new ErrorProvider.ErrorMessage("ERROR_CONVERTFROM"), ex);
            }
        }
示例#5
0
        public static PointLatLngAlt FromUTM(int zone,double x, double y)
        {
            GeoUtility.GeoSystem.UTM utm = new GeoUtility.GeoSystem.UTM(Math.Abs(zone), x, y, zone < 0 ? GeoUtility.GeoSystem.Base.Geocentric.Hemisphere.South : GeoUtility.GeoSystem.Base.Geocentric.Hemisphere.North);

            PointLatLngAlt ans = ((GeoUtility.GeoSystem.Geographic)utm);

            return ans;
        }
示例#6
0
        /// <summary><para>Die statische Methode kann dazu verwendet werden, als String-Werte übergebene UTM Parameter
        /// auf ihre Gültigkeit zu überprüfen. Die Methode gibt eine Liste gültiger Parameter, eine Fehlermeldung und
        /// ein <see cref="UTM"/>-Objekt zurück. Ist einer der Parameter ungültig, wird ein <see cref="UTM"/>-Objekt
        /// mir dem Wert null zurückgegeben.</para></summary>
        /// <param name="Zone">Zone als Typ <see cref="System.String"/>.</param>
        /// <param name="Band">Band als Typ <see cref="System.String"/>.</param>
        /// <param name="East">East-Wert als Typ <see cref="System.String"/>.</param>
        /// <param name="North">North-Wert als Typ <see cref="System.String"/>.</param>
        /// <param name="Utm">Ein gültiges <see cref="UTM"/>-Objekt oder null.</param>
        /// <param name="ErrorMessage">Eine ausführliche Fehlermeldung, falls ein Fehler aufgetreten ist.</param>
        /// <param name="ValidItems">Ein <see cref="System.Collections.Generic.Dictionary{T, T}"/>-Objekt, in dem die gültigen und ungültigen Parameter aufgeführt werden.</param>
        /// <returns>True, wenn alle Parameter gültig sind, sonst False.</returns>
        static public bool TryParse(string Zone, string Band, string East, string North, out UTM Utm, out string ErrorMessage, out Dictionary <string, bool> ValidItems)
        {
            bool                      result = true;
            bool                      converted = true;
            StringBuilder             sb = new StringBuilder();
            UTM                       utm = null;
            Dictionary <string, bool> list = new Dictionary <string, bool>();
            int                       zone = 0, east = 0, north = 0;
            char                      band = 'A';

            Band = Band.ToUpper();

            try { zone = int.Parse(Zone); } catch { converted = false; }
            if ((zone < 1) || (zone > 60))
            {
                converted = false;
            }
            list.Add("Zone", converted);
            if (list["Zone"] == false)
            {
                sb.Append(new ErrorProvider.ErrorMessage("ERROR_UTM_ZONE2").Text + "\r\n");
                result = false;
            }
            converted = true;

            converted = char.IsLetter(Band, 0);
            try { band = Convert.ToChar(Band); } catch { converted = false; }
            if ((band < 'C') || (band > 'X') || (band == 'I') || (band == 'O'))
            {
                converted = false;
            }
            list.Add("Band", converted);
            if (list["Band"] == false)
            {
                sb.Append(new ErrorProvider.ErrorMessage("ERROR_UTM_Band").Text + "\r\n");
                result = false;
            }
            converted = true;

            try { east = int.Parse(East); } catch { converted = false; }
            if ((east < 160000) || (east > 840000))
            {
                converted = false;
            }
            list.Add("East", converted);
            if (list["East"] == false)
            {
                sb.Append(new ErrorProvider.ErrorMessage("ERROR_UTM_EAST").Text + "\r\n");
                result = false;
            }
            converted = true;

            try { north = int.Parse(North); } catch { converted = false; }
            if ((band <= 'M' && ((north < 1116915) || (north > 10000000))) || (band >= 'N' && ((north < 0) || (north > 9329005))))
            {
                converted = false;
            }
            list.Add("North", converted);
            if (list["North"] == false)
            {
                sb.Append(new ErrorProvider.ErrorMessage("ERROR_UTM_NORTH").Text + "\r\n");
                result = false;
            }

            if (result == true)
            {
                utm = new UTM(zone, band.ToString(), east, north);
            }
            Utm          = utm;
            ErrorMessage = sb.ToString();
            ValidItems   = list;
            return(result);
        }