/// <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); }
/// <summary><para>Die statische Methode kann dazu verwendet werden, einen zusammengesetzten MGRS-String /// auf seine Gültigkeit zu überprüfen. eine Fehlermeldung und /// ein <see cref="MGRS"/>-Objekt zurück. Ist einer der Parameter ungültig, wird ein <see cref="MGRS"/>-Objekt /// mir dem Wert null zurückgegeben.</para></summary> /// <param name="mstring">MGRS Koordinatenstring als Typ <see cref="System.String"/>.</param> /// <param name="Mgrs">Ein gültiges <see cref="MGRS"/>-Objekt oder null.</param> /// <param name="ErrorMessage">Eine ausführliche Fehlermeldung, falls ein Fehler aufgetreten ist.</param> /// <returns>True, wenn alle Parameter gültig sind, sonst False.</returns> static public bool TryParse(string mstring, out MGRS Mgrs, out string ErrorMessage) { string message = ""; MGRS mgrs = new MGRS(); bool result = true; try { mstring = mstring.Replace(" ", ""); mstring = mstring.ToUpper(); // Mindestens Zone (1), Band (1), Grid (2), East (1), North (1) = 6 if (mstring.Length < 6) { throw new ErrorProvider.GeoException(new ErrorProvider.ErrorMessage("ERROR_MGRS")); } int zone = 0; // Test auf 1 oder 2-stellige Zonenangabe if (char.IsDigit(Convert.ToChar(mstring.Substring(0, 1)))) { if (char.IsDigit(Convert.ToChar(mstring.Substring(1, 1)))) { zone = int.Parse(mstring.Substring(0, 2)); mstring = mstring.Remove(0, 2); } else { zone = int.Parse(mstring.Substring(0, 1)); mstring = mstring.Remove(0, 1); } } else { throw new ErrorProvider.GeoException(new ErrorProvider.ErrorMessage("ERROR_MGRS")); } mgrs.Zone = zone; if (mstring.Length < 5) { throw new ErrorProvider.GeoException(new ErrorProvider.ErrorMessage("ERROR_MGRS")); } char band = mstring.Substring(0, 1).ToCharArray()[0]; if ((band < 'C') || (band > 'X') || (band == 'I') || (band == 'O')) { throw new ErrorProvider.GeoException(new ErrorProvider.ErrorMessage("ERROR_MGRS_GRID")); } mgrs.Band = band.ToString(); mstring = mstring.Remove(0, 1); string grid = mstring.Substring(0, 2); char c0 = grid.ToCharArray()[0]; char c1 = grid.ToCharArray()[1]; if ((c0 < 'A') || (c0 >= 'Z') || (c1 < 'A') || (c1 >= 'Z') || (c0 == 'I') || (c0 == 'O') || (c1 == 'I') || (c1 == 'O')) { throw new ErrorProvider.GeoException(new ErrorProvider.ErrorMessage("ERROR_MGRS_GRID")); } mgrs.Grid = grid; mstring = mstring.Remove(0, 2); if (mstring.Length % 2 > 0) { throw new ErrorProvider.GeoException(new ErrorProvider.ErrorMessage("ERROR_MGRS")); } int len = mstring.Length / 2; string eaststring = mstring.Substring(0, len); mstring = mstring.Remove(0, len); string northstring = mstring; if (eaststring.Length > 5) { eaststring = eaststring.Substring(0, 5); } else if (eaststring.Length < 5) { eaststring = eaststring.PadRight(5, '0'); } if (northstring.Length > 5) { northstring = northstring.Substring(0, 5); } else if (northstring.Length < 5) { northstring = northstring.PadRight(5, '0'); } mgrs.East = double.Parse(eaststring); mgrs.North = double.Parse(northstring); } catch { mgrs = null; result = false; message = new ErrorProvider.ErrorMessage("ERROR_MGRS").Text; } Mgrs = mgrs; ErrorMessage = message; return(result); }
/// <summary><para>Die überladene Funktion <see cref="Load(Info.MapServiceTileBase, bool)"/> lädt das Satellitenbild, welches durch den Parameter vom Typ /// <see cref="MapService.Info.MapServiceTileBase"/> festgelegt wurde von dem gewünschten MapService-Provider. /// Ein Beispiel ist in der Funktion <see cref="Load()"/> zu finden.</para></summary> /// /// <param name="tile">Ein Objekt vom Typ <see cref="MapService.Info.MapServiceTileBase"/>, das über die <see cref="MapService.Tile"/>-Eigenschaft des <see cref="MapService"/>-Objektes erhalten werden kann.</param> /// <param name="silent">Legt fest, ob im Fehlerfall eine Exception weitergegeben wird (false) oder nicht (true).</param> /// <returns>Ein Bild vom allgemeinen Typ <see cref="System.Drawing.Image"/>.</returns> public Image Load(Info.MapServiceTileBase tile, bool silent) { Image image = null; Stream data = null; HttpWebResponse response = null; // Erst versuchen Bild, aus dem Cach zu holen if (MapService.Helper.Images.Cache.Enabled == true) { image = MapService.Helper.Images.Cache.GetImage(this.Parent); if (image != null) { return(image); } } // Bild nicht im Cache, oder Cache nicht verwendet if ((tile != null) && (tile.URL != "")) { System.Net.HttpWebRequest request = (HttpWebRequest)WebRequest.Create(tile.URL); request.UserAgent = USER_AGENT; request.Timeout = 30000; try { response = (HttpWebResponse)request.GetResponse(); data = response.GetResponseStream(); image = new Bitmap(data); // Fehlerbild Virtual Earth und Yahoo Maps erkennen if (this.Parent.MapServer != Info.MapServer.GoogleMaps) { bool isValidImage = ValidImage(image); ErrorProvider.ErrorMessage err = new ErrorProvider.ErrorMessage("MS_NO_IMAGE"); if (isValidImage == false) { throw new WebException(err.Text, WebExceptionStatus.ProtocolError); } } // Bild im Cache ablegen if (MapService.Helper.Images.Cache.Enabled == true) { MapService m; if (tile.URL == Parent.Tile.URL) { m = this.Parent.MemberwiseClone(); } else { m = new MapService(tile); } MapService.Helper.Images.Cache.Add(new CacheItem(m, image)); } } catch (WebException ex) { image = null; if (!silent) { throw new Exception(ex.Message, ex); } } catch (Exception ex) { image = null; if (!silent) { throw new Exception(ex.Message, ex); } } finally { if (response != null) { response.Close(); } if (data != null) { data.Close(); } } } return(image); }