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> /// 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); } }