private void DDMMMtoDDD() { // Now it's tricky... String c = tbLatLonDDMMM.Text; c = c.TrimStart(null); c = c.TrimEnd(null); int iNS = Math.Max(c.IndexOf("N"), c.IndexOf("S")); int iEW = Math.Max(c.IndexOf("E"), c.IndexOf("W")); if ((iNS == -1) || (iEW == -1)) { tbLatLonDDD.Text = CoordConvHMI._sErrorValue; } String c1 = ""; String c2 = ""; if (iNS < iEW) { c1 = c.Substring(0, iEW); c2 = c.Substring(iEW); } else { c2 = c.Substring(0, iNS); c1 = c.Substring(iNS); } tbLatLonDDD.Text = CoordConvHMI.OneConvertDDMMM2DDD(c1, "S", "N", true) + " " + CoordConvHMI.OneConvertDDMMM2DDD(c2, "W", "E", false); }
/// <summary> /// Check if longitude and latitude in decimal degrees are within valid range /// </summary> /// <param name="decimal_degrees">longitude or latitude</param> /// <param name="bLat">True if latitude</param> /// <returns>true if value is correct</returns> static public bool CheckLonLatValidity(String decimal_degrees, bool bLat) { try { double coord = MyTools.ConvertToDouble(decimal_degrees); return(CoordConvHMI.CheckLonLatValidity(coord, bLat)); } catch (Exception) { return(false); } }
/// <summary> /// Check if longitude and latitude in decimal degrees are within valid range /// </summary> /// <param name="decimal_degrees_lon">longitude in decimal degrees (-180 / +180)</param> /// <param name="decimal_degrees_lat">latitude in decimal degrees (-90 / +90)</param> /// <returns>true if both values are correct</returns> static public bool CheckLonLatValidity(String decimal_degrees_lon, String decimal_degrees_lat) { try { double lon = MyTools.ConvertToDouble(decimal_degrees_lon); double lat = MyTools.ConvertToDouble(decimal_degrees_lat); return(CoordConvHMI.CheckLonLatValidity(lon, lat)); } catch (Exception) { return(false); } }
/// <summary> /// converts coordinates from DDMMM to DDD /// From DD° MM.MMM : N 48° 46.164 E 01° 58.048 /// To DD.DDDDDD : 48.769408 1.967473 /// </summary> /// <param name="LatLonDDMMM">coordinates to convert</param> /// <param name="sLat">output, N or S</param> /// <param name="sLon">output, E or W</param> /// <returns>true if coordinates are valid</returns> static public bool DDMMMtoDDD(String LatLonDDMMM, ref String sLat, ref String sLon) { // Now it's tricky... String c = LatLonDDMMM; c = c.TrimStart(null); c = c.TrimEnd(null); int iNS = Math.Max(c.IndexOf("N"), c.IndexOf("S")); int iEW = Math.Max(c.IndexOf("E"), c.IndexOf("W")); if ((iNS == -1) || (iEW == -1)) { return(false); } String c1 = ""; String c2 = ""; if (iNS < iEW) { c1 = c.Substring(0, iEW); c2 = c.Substring(iEW); } else { c2 = c.Substring(0, iNS); c1 = c.Substring(iNS); } sLat = CoordConvHMI.OneConvertDDMMM2DDD(c1, "S", "N", true); sLon = CoordConvHMI.OneConvertDDMMM2DDD(c2, "W", "E", false); if ((sLat != CoordConvHMI._sErrorValue) && (sLon != CoordConvHMI._sErrorValue)) { return(true); } else { return(false); } }