상속: CoordinateBase
        private static void PlaceHemiSphereIndicator(string format, CoordinateDMS coord, StringBuilder sb, int latIndex, int lonIndex, List <int> closingIndexes)
        {
            if (lonIndex != -1 && latIndex != -1)
            {
                int lonVal = -1, latVal = -1;
                if (closingIndexes.Where(x => x < lonIndex).Any())
                {
                    lonVal = closingIndexes.Max();
                    latVal = closingIndexes.Where(x => x < lonIndex).Max();
                }
                else
                {
                    lonVal = closingIndexes.Where(x => x < latIndex).Max();
                    latVal = closingIndexes.Max();
                }

                var nextLatChar = sb.ToString().ElementAt(latVal);
                var skipLatChar = ((nextLatChar == '"' & format.Contains('C'))
                                   | (nextLatChar == '\'' & format.Contains('B'))
                                   | (nextLatChar == '°' & format.Contains('A')));

                var nextLonChar = sb.ToString().ElementAt(lonVal);
                var skipLonChar = ((nextLonChar == '"' & format.Contains('Z'))
                                   | (nextLonChar == '\'' & format.Contains('Y'))
                                   | (nextLonChar == '°' & format.Contains('X')));
                if (coord.LonDegrees > 0.0)
                {
                    if (CoordinateBase.ShowHemisphere | CoordinateBase.IsOutputInProcess)
                    {
                        sb.Insert(skipLonChar ? lonVal + 1 : lonVal, "E");
                    }
                }
                else
                {
                    if (CoordinateBase.ShowHemisphere | CoordinateBase.IsOutputInProcess)
                    {
                        sb.Insert(skipLonChar ? lonVal + 1 : lonVal, "W");
                    }
                }
                if (coord.LatDegrees > 0.0)
                {
                    if (CoordinateBase.ShowHemisphere | CoordinateBase.IsOutputInProcess)
                    {
                        sb.Insert(skipLatChar ? latVal + 1 : latVal, "N");
                    }
                }
                else
                {
                    if (CoordinateBase.ShowHemisphere | CoordinateBase.IsOutputInProcess)
                    {
                        sb.Insert(skipLatChar ? latVal + 1 : latVal, "S");
                    }
                }
            }
        }
        public static bool TryParse(string input, out CoordinateDMS dms)
        {
            dms = new CoordinateDMS();

            if (string.IsNullOrWhiteSpace(input))
            {
                return(false);
            }

            input = input.Trim();

            Regex regexDMS = new Regex("^ *[+]*(?<latitudeSuffix>[NS])?(?<latitudeD>[^NSDd*° ,:]*)?[Dd*° ,:]*(?<latitudeM>[^NS' ,:]*)?[' ,:]*(?<latitudeS>[^NS\\\" ,:]*)?[\\\" ,:]*(?<latitudeSuffix>[NS])? *[+,]*(?<longitudeSuffix>[EW])?(?<longitudeD>[^EWDd*° ,:]*)?[Dd*° ,:]*(?<longitudeM>[^EW' ,:]*)?[' ,:]*(?<longitudeS>[^EW\\\" ,:]*)?[\\\" ,:]*(?<longitudeSuffix>[EW])?[\\\"]*", RegexOptions.ExplicitCapture);

            var matchDMS = regexDMS.Match(input);

            if (matchDMS.Success && matchDMS.Length == input.Length)
            {
                if (ValidateNumericCoordinateMatch(matchDMS, new string[] { "latitudeD", "latitudeM", "latitudeS", "longitudeD", "longitudeM", "longitudeS" }))
                {
                    try
                    {
                        var LatDegrees = int.Parse(matchDMS.Groups["latitudeD"].Value);
                        var LatMinutes = int.Parse(matchDMS.Groups["latitudeM"].Value);
                        var LatSeconds = double.Parse(matchDMS.Groups["latitudeS"].Value);
                        var LonDegrees = int.Parse(matchDMS.Groups["longitudeD"].Value);
                        var LonMinutes = int.Parse(matchDMS.Groups["longitudeM"].Value);
                        var LonSeconds = double.Parse(matchDMS.Groups["longitudeS"].Value);

                        var temp = matchDMS.Groups["latitudeSuffix"];
                        if (temp.Success && temp.Value.ToUpper().Equals("S"))
                        {
                            LatDegrees = Math.Abs(LatDegrees) * -1;
                        }
                        temp = matchDMS.Groups["longitudeSuffix"];
                        if (temp.Success && temp.Value.ToUpper().Equals("W"))
                        {
                            LonDegrees = Math.Abs(LonDegrees) * -1;
                        }

                        dms = new CoordinateDMS(LatDegrees, LatMinutes, LatSeconds, LonDegrees, LonMinutes, LonSeconds);
                    }
                    catch
                    {
                        return(false);
                    }

                    return(true);
                }
            }
            return(false);
        }
예제 #3
0
 public CoordinateDD(CoordinateDMS dms)
 {
     Lat = (double)dms.LatDegrees + ((double)dms.LatMinutes / 60.0) + (dms.LatSeconds / 3600.0);
     Lon = (double)dms.LonDegrees + ((double)dms.LonMinutes / 60.0) + (dms.LatSeconds / 3600.0);
 }
예제 #4
0
 public CoordinateDD(CoordinateDMS dms)
 {
     Lat = (Math.Abs((double)dms.LatDegrees) + ((double)dms.LatMinutes / 60.0) + (dms.LatSeconds / 3600.0)) * ((dms.LatDegrees < 0) ? -1.0 : 1.0);
     Lon = (Math.Abs((double)dms.LonDegrees) + ((double)dms.LonMinutes / 60.0) + (dms.LonSeconds / 3600.0)) * ((dms.LonDegrees < 0) ? -1.0 : 1.0);
 }
        public static bool TryParse(string input, out CoordinateDMS dms)
        {
            dms = new CoordinateDMS();

            if (string.IsNullOrWhiteSpace(input))
            {
                return(false);
            }

            input = input.Trim();
            string numSep = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;

            input = numSep != "." ? input.Replace(".", numSep) : input;

            Regex regexDMSLat = new Regex(@"^((?<firstPrefix>[\+\-NnSs])?(?<latitudeD>[0-8]?\d|90)[°˚º^~*\s\-_]+(?<latitudeM>[0-5]?\d|\d)['′\s\-_]+(?<latitudeS>([0-5]?\d|\d)([.,:]\d*)?)[\u0022\u00A8\u02DD\s_]*(?<firstSuffix>[\+\-NnSs])?)([,:;\s|\/\\]+)((?<lastPrefix>[\+\-EeWw])?(?<longitudeD>[0]?\d?\d|1[0-7]\d|180)[°˚º^~*\s\-_]+(?<longitudeM>[0-5]\d|\d)['′\s\-_]+(?<longitudeS>([0-5]?\d|\d)([.,:]\d*)?)[\u0022\u00A8\u02DD\s_]*(?<lastSuffix>[\+\-EeWw])?)[\s]*$");
            Regex regexDMSLon = new Regex(@"^((?<firstPrefix>[\+\-EeWw])?(?<longitudeD>[0]?\d?\d|1[0-7]\d|180)[°˚º^~*\s\-_]+(?<longitudeM>[0-5]\d|\d)['′\s\-_]+(?<longitudeS>([0-5]?\d|\d)([.,:]\d*)?)[\u0022\u00A8\u02DD\s_]*(?<firstSuffix>[\+\-EeWw])?)([,:;\s|\/\\]+)((?<lastPrefix>[\+\-NnSs])?(?<latitudeD>[0-8]?\d|90)[°˚º^~*\s\-_]+(?<latitudeM>[0-5]?\d|\d)['′\s\-_]+(?<latitudeS>([0-5]?\d|\d)([.,:]\d*)?)[\u0022\u00A8\u02DD\s_]*(?<lastSuffix>[\+\-NnSs])?)[\s]*$");

            var matchDMSLat = regexDMSLat.Match(input);
            var matchDMSLon = regexDMSLon.Match(input);

            bool   blnMatchDMSLat = matchDMSLat.Success;
            int    LatDegrees = -1, LonDegrees = -1, LatMinutes = -1, LonMinutes = -1;
            double LatSeconds = -1, LonSeconds = -1;
            Group  firstPrefix = null, firstSuffix = null, lastPrefix = null, lastSuffix = null;

            // Ambiguous coordinate, could be both lat/lon && lon/lat
            if (matchDMSLat.Success && matchDMSLat.Length == input.Length && matchDMSLon.Success && matchDMSLon.Length == input.Length)
            {
                if (CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg)
                {
                    ambiguousCoordsViewDlg.ShowDialog();
                }

                blnMatchDMSLat = ambiguousCoordsViewDlg.CheckedLatLon;
            }

            // Lat/Lon
            if (matchDMSLat.Success && matchDMSLat.Length == input.Length && blnMatchDMSLat)
            {
                if (ValidateNumericCoordinateMatch(matchDMSLat, new string[] { "latitudeD", "latitudeM", "latitudeS", "longitudeD", "longitudeM", "longitudeS" }))
                {
                    LatDegrees  = int.Parse(matchDMSLat.Groups["latitudeD"].Value);
                    LatMinutes  = int.Parse(matchDMSLat.Groups["latitudeM"].Value);
                    LatSeconds  = double.Parse(matchDMSLat.Groups["latitudeS"].Value);
                    LonDegrees  = int.Parse(matchDMSLat.Groups["longitudeD"].Value);
                    LonMinutes  = int.Parse(matchDMSLat.Groups["longitudeM"].Value);
                    LonSeconds  = double.Parse(matchDMSLat.Groups["longitudeS"].Value);
                    firstPrefix = matchDMSLat.Groups["firstPrefix"];
                    firstSuffix = matchDMSLat.Groups["firstSuffix"];
                    lastPrefix  = matchDMSLat.Groups["lastPrefix"];
                    lastSuffix  = matchDMSLat.Groups["lastSuffix"];

                    blnMatchDMSLat = true;
                }
                else
                {
                    return(false);
                }
            }
            // Lon/Lat
            else if (matchDMSLon.Success && matchDMSLon.Length == input.Length)
            {
                if (ValidateNumericCoordinateMatch(matchDMSLon, new string[] { "latitudeD", "latitudeM", "latitudeS", "longitudeD", "longitudeM", "longitudeS" }))
                {
                    LatDegrees  = int.Parse(matchDMSLon.Groups["latitudeD"].Value);
                    LatMinutes  = int.Parse(matchDMSLon.Groups["latitudeM"].Value);
                    LatSeconds  = double.Parse(matchDMSLon.Groups["latitudeS"].Value);
                    LonDegrees  = int.Parse(matchDMSLon.Groups["longitudeD"].Value);
                    LonMinutes  = int.Parse(matchDMSLon.Groups["longitudeM"].Value);
                    LonSeconds  = double.Parse(matchDMSLon.Groups["longitudeS"].Value);
                    firstPrefix = matchDMSLon.Groups["firstPrefix"];
                    firstSuffix = matchDMSLon.Groups["firstSuffix"];
                    lastPrefix  = matchDMSLon.Groups["lastPrefix"];
                    lastSuffix  = matchDMSLon.Groups["lastSuffix"];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            // Don't allow both prefix and suffix for lat or lon
            if (firstPrefix.Success && firstSuffix.Success)
            {
                return(false);
            }

            if (lastPrefix.Success && lastSuffix.Success)
            {
                return(false);
            }

            if ((firstSuffix.Success || firstPrefix.Success) && (firstSuffix.Value.ToUpper().Equals("S") || firstPrefix.Value.ToUpper().Equals("S")) ||
                (lastSuffix.Success || lastPrefix.Success) && (lastSuffix.Value.ToUpper().Equals("S") || lastPrefix.Value.ToUpper().Equals("S")))
            {
                LatDegrees = Math.Abs(LatDegrees) * -1;
            }

            if ((firstSuffix.Success || firstPrefix.Success) && (firstSuffix.Value.ToUpper().Equals("W") || firstPrefix.Value.ToUpper().Equals("W")) ||
                (lastSuffix.Success || lastPrefix.Success) && (lastSuffix.Value.ToUpper().Equals("W") || lastPrefix.Value.ToUpper().Equals("W")))
            {
                LonDegrees = Math.Abs(LonDegrees) * -1;
            }

            if ((firstSuffix.Success || firstPrefix.Success) && (firstSuffix.Value.ToUpper().Equals("-") || firstPrefix.Value.ToUpper().Equals("-")))
            {
                if (blnMatchDMSLat)
                {
                    LatDegrees = Math.Abs(LatDegrees) * -1;
                }
                else
                {
                    LonDegrees = Math.Abs(LonDegrees) * -1;
                }
            }

            if ((lastSuffix.Success || lastPrefix.Success) && (lastSuffix.Value.ToUpper().Equals("-") || lastPrefix.Value.ToUpper().Equals("-")))
            {
                if (blnMatchDMSLat)
                {
                    LonDegrees = Math.Abs(LonDegrees) * -1;
                }
                else
                {
                    LatDegrees = Math.Abs(LatDegrees) * -1;
                }
            }

            dms = new CoordinateDMS(LatDegrees, LatMinutes, LatSeconds, LonDegrees, LonMinutes, LonSeconds);

            return(true);
        }
 public override bool CanGetDMS(int srFactoryCode, out string coord)
 {
     coord = string.Empty;
     if (base.CanGetDMS(srFactoryCode, out coord))
     {
         return true;
     }
     else
     {
         if (base.CanGetDD(srFactoryCode, out coord))
         {
             // convert dd to ddm
             CoordinateDD dd;
             if (CoordinateDD.TryParse(coord, out dd))
             {
                 var dms = new CoordinateDMS(dd);
                 coord = dms.ToString("", new CoordinateDMSFormatter());
                 return true;
             }
         }
     }
     return false;
 }
        public static string GetFormattedCoord(CoordinateType cType, string coord, string format)
        {
            if (cType == CoordinateType.DD)
            {
                CoordinateDD dd;
                if (CoordinateDD.TryParse(coord, out dd, true))
                {
                    return(dd.ToString(format, new CoordinateDDFormatter()));
                }
            }
            if (cType == CoordinateType.DDM)
            {
                CoordinateDDM ddm;
                if (CoordinateDDM.TryParse(coord, out ddm, true))
                {
                    return(ddm.ToString(format, new CoordinateDDMFormatter()));
                }
            }
            if (cType == CoordinateType.DMS)
            {
                CoordinateDMS dms;
                if (CoordinateDMS.TryParse(coord, out dms, true))
                {
                    return(dms.ToString(format, new CoordinateDMSFormatter()));
                }
            }
            if (cType == CoordinateType.GARS)
            {
                CoordinateGARS gars;
                if (CoordinateGARS.TryParse(coord, out gars))
                {
                    return(gars.ToString(format, new CoordinateGARSFormatter()));
                }
            }
            if (cType == CoordinateType.MGRS)
            {
                CoordinateMGRS mgrs;
                if (CoordinateMGRS.TryParse(coord, out mgrs))
                {
                    return(mgrs.ToString(format, new CoordinateMGRSFormatter()));
                }
            }
            if (cType == CoordinateType.USNG)
            {
                CoordinateUSNG usng;
                if (CoordinateUSNG.TryParse(coord, out usng))
                {
                    return(usng.ToString(format, new CoordinateMGRSFormatter()));
                }
            }
            if (cType == CoordinateType.UTM)
            {
                CoordinateUTM utm;
                if (CoordinateUTM.TryParse(coord, out utm))
                {
                    return(utm.ToString(format, new CoordinateUTMFormatter()));
                }
            }

            return(null);
        }
        public static bool TryParse(string input, out CoordinateDMS dms)
        {
            dms = new CoordinateDMS();

            if (string.IsNullOrWhiteSpace(input))
                return false;

            input = input.Trim();

            Regex regexDMS = new Regex("^ *[+]*(?<latitudeSuffix>[NS])?(?<latitudeD>[^NSDd*° ,:]*)?[Dd*° ,:]*(?<latitudeM>[^NS' ,:]*)?[' ,:]*(?<latitudeS>[^NS\\\" ,:]*)?[\\\" ,:]*(?<latitudeSuffix>[NS])? *[+,]*(?<longitudeSuffix>[EW])?(?<longitudeD>[^EWDd*° ,:]*)?[Dd*° ,:]*(?<longitudeM>[^EW' ,:]*)?[' ,:]*(?<longitudeS>[^EW\\\" ,:]*)?[\\\" ,:]*(?<longitudeSuffix>[EW])?[\\\"]*", RegexOptions.ExplicitCapture);

            var matchDMS = regexDMS.Match(input);

            if (matchDMS.Success && matchDMS.Length == input.Length)
            {
                if (ValidateNumericCoordinateMatch(matchDMS, new string[] { "latitudeD", "latitudeM", "latitudeS", "longitudeD", "longitudeM", "longitudeS" }))
                {
                    try
                    {
                        var LatDegrees = int.Parse(matchDMS.Groups["latitudeD"].Value);
                        var LatMinutes = int.Parse(matchDMS.Groups["latitudeM"].Value);
                        var LatSeconds = double.Parse(matchDMS.Groups["latitudeS"].Value);
                        var LonDegrees = int.Parse(matchDMS.Groups["longitudeD"].Value);
                        var LonMinutes = int.Parse(matchDMS.Groups["longitudeM"].Value);
                        var LonSeconds = double.Parse(matchDMS.Groups["longitudeS"].Value);

                        var temp = matchDMS.Groups["latitudeSuffix"];
                        if (temp.Success && temp.Value.ToUpper().Equals("S"))
                        {
                            LatDegrees = Math.Abs(LatDegrees) * -1;
                        }
                        temp = matchDMS.Groups["longitudeSuffix"];
                        if (temp.Success && temp.Value.ToUpper().Equals("W"))
                        {
                            LonDegrees = Math.Abs(LonDegrees) * -1;
                        }

                        dms = new CoordinateDMS(LatDegrees, LatMinutes, LatSeconds, LonDegrees, LonMinutes, LonSeconds);
                    }
                    catch
                    {
                        return false;
                    }

                    return true;
                }
            }
            return false;
        }
 public CoordinateDD(CoordinateDMS dms)
 {
     Lat = (double)dms.LatDegrees + ((double)dms.LatMinutes / 60.0) + (dms.LatSeconds / 3600.0);
     Lon = (double)dms.LonDegrees + ((double)dms.LonMinutes / 60.0) + (dms.LatSeconds / 3600.0);
 }
        private void UpdateSample()
        {
            var type = GetCoordinateType();

            switch(type)
            {
                case CoordinateType.DD:
                    var dd = new CoordinateDD();

                    if (ctdict.ContainsKey(CoordinateType.DD))
                    {
                        CoordinateDD.TryParse(ctdict[type], out dd);
                    }

                    Sample = dd.ToString(Format, new CoordinateDDFormatter());

                    break;
                case CoordinateType.DDM:
                    var ddm = new CoordinateDDM();

                    if(ctdict.ContainsKey(type))
                    {
                        CoordinateDDM.TryParse(ctdict[type], out ddm);
                    }

                    Sample = ddm.ToString(Format, new CoordinateDDMFormatter());
                    break;
                case CoordinateType.DMS:
                    var dms = new CoordinateDMS();

                    if(ctdict.ContainsKey(type))
                    {
                        CoordinateDMS.TryParse(ctdict[type], out dms);
                    }
                    Sample = dms.ToString(Format, new CoordinateDMSFormatter());
                    break;
                case CoordinateType.GARS:
                    var gars = new CoordinateGARS();

                    if(ctdict.ContainsKey(type))
                    {
                        CoordinateGARS.TryParse(ctdict[type], out gars);
                    }

                    Sample = gars.ToString(Format, new CoordinateGARSFormatter());
                    break;
                case CoordinateType.MGRS:
                    var mgrs = new CoordinateMGRS();

                    if(ctdict.ContainsKey(type))
                    {
                        CoordinateMGRS.TryParse(ctdict[type], out mgrs);
                    }

                    Sample = mgrs.ToString(Format, new CoordinateMGRSFormatter());
                    break;
                case CoordinateType.USNG:
                    var usng = new CoordinateUSNG();

                    if(ctdict.ContainsKey(type))
                    {
                        CoordinateUSNG.TryParse(ctdict[type], out usng);
                    }

                    Sample = usng.ToString(Format, new CoordinateMGRSFormatter());
                    break;
                case CoordinateType.UTM:
                    var utm = new CoordinateUTM();

                    if(ctdict.ContainsKey(type))
                    {
                        CoordinateUTM.TryParse(ctdict[type], out utm);
                    }

                    Sample = utm.ToString(Format, new CoordinateUTMFormatter());
                    break;
                default:
                    break;
            }

            RaisePropertyChanged(() => Sample);
        }
예제 #11
0
        public static bool TryParse(string input, out CoordinateDMS dms)
        {
            dms = new CoordinateDMS();

            if (string.IsNullOrWhiteSpace(input))
            {
                return(false);
            }

            input = input.Trim();
            string numSep = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;

            input = numSep != "." ? input.Replace(".", numSep) : input;

            Regex regexDMS = new Regex(@"^(?i) *[+]*(?<firstPrefix>[NSEW])?(?<latitudeD>\-*\d{1,3})?[°˚º^~*\s\-_]+(?<latitudeM>\d+)['′]*[ _-]*(?<latitudeS>(?=\d+[.,:]\d+)(\d+[.,:]\d*)|(\d+))[""]*(?<firstSuffix>[NSEW])?[,\s |\/\\]*[+]*(?<lastPrefix>[NSEW])?(?<longitudeD>\-*\d{1,3})?[°˚º^~*\s\-_]+(?<longitudeM>\d+)['′]?[_ -]*(?<longitudeS>\d+[.,:]?\d*)[""]*(?<lastSuffix>[NSEW])?", RegexOptions.ExplicitCapture);

            var matchDMS = regexDMS.Match(input);

            if (matchDMS.Success && matchDMS.Length == input.Length)
            {
                if (ValidateNumericCoordinateMatch(matchDMS, new string[] { "latitudeD", "latitudeM", "latitudeS", "longitudeD", "longitudeM", "longitudeS" }))
                {
                    try
                    {
                        var firstPrefix = matchDMS.Groups["firstPrefix"];
                        var firstSuffix = matchDMS.Groups["firstSuffix"];
                        var lastPrefix  = matchDMS.Groups["lastPrefix"];
                        var lastSuffix  = matchDMS.Groups["lastSuffix"];

                        // Don't allow both prefix and suffix for lat or lon
                        if ((firstPrefix.Success && firstSuffix.Success) && (firstPrefix.Length > 0 && firstSuffix.Length > 0))
                        {
                            return(false);
                        }

                        if ((lastPrefix.Success && lastSuffix.Success) && (lastPrefix.Length > 0 && lastSuffix.Length > 0))
                        {
                            return(false);
                        }

                        // Don't allow same prefix/suffix for both lat and lon
                        if ((firstSuffix.Success || firstPrefix.Success) && (firstSuffix.Value.ToUpper().Equals("E") || firstPrefix.Value.ToUpper().Equals("E") ||
                                                                             firstSuffix.Value.ToUpper().Equals("W") || firstPrefix.Value.ToUpper().Equals("W")) &&
                            (lastSuffix.Success || lastPrefix.Success) && (lastSuffix.Value.ToUpper().Equals("E") || lastPrefix.Value.ToUpper().Equals("E") ||
                                                                           lastSuffix.Value.ToUpper().Equals("W") || lastPrefix.Value.ToUpper().Equals("W")))
                        {
                            return(false);
                        }

                        if ((firstSuffix.Success || firstPrefix.Success) && (firstSuffix.Value.ToUpper().Equals("N") || firstPrefix.Value.ToUpper().Equals("N") ||
                                                                             firstSuffix.Value.ToUpper().Equals("S") || firstPrefix.Value.ToUpper().Equals("S")) &&
                            (lastSuffix.Success || lastPrefix.Success) && (lastSuffix.Value.ToUpper().Equals("N") || lastPrefix.Value.ToUpper().Equals("N") ||
                                                                           lastSuffix.Value.ToUpper().Equals("S") || lastPrefix.Value.ToUpper().Equals("S")))
                        {
                            return(false);
                        }

                        var LatDegrees = int.Parse(matchDMS.Groups["latitudeD"].Value);
                        var LatMinutes = int.Parse(matchDMS.Groups["latitudeM"].Value);
                        var LatSeconds = double.Parse(matchDMS.Groups["latitudeS"].Value);
                        var LonDegrees = int.Parse(matchDMS.Groups["longitudeD"].Value);
                        var LonMinutes = int.Parse(matchDMS.Groups["longitudeM"].Value);
                        var LonSeconds = double.Parse(matchDMS.Groups["longitudeS"].Value);

                        // if E/W is in first coordinate or N/S is in second coordinate then flip the lat/lon values
                        if ((firstSuffix.Success || firstPrefix.Success) && (firstSuffix.Value.ToUpper().Equals("E") || firstPrefix.Value.ToUpper().Equals("E") ||
                                                                             firstSuffix.Value.ToUpper().Equals("W") || firstPrefix.Value.ToUpper().Equals("W")) ||
                            (lastSuffix.Success || lastPrefix.Success) && (lastSuffix.Value.ToUpper().Equals("N") || lastPrefix.Value.ToUpper().Equals("N") ||
                                                                           lastSuffix.Value.ToUpper().Equals("S") || lastPrefix.Value.ToUpper().Equals("S")))
                        {
                            LatDegrees = int.Parse(matchDMS.Groups["longitudeD"].Value);
                            LatMinutes = int.Parse(matchDMS.Groups["longitudeM"].Value);
                            LatSeconds = double.Parse(matchDMS.Groups["longitudeS"].Value);
                            LonDegrees = int.Parse(matchDMS.Groups["latitudeD"].Value);
                            LonMinutes = int.Parse(matchDMS.Groups["latitudeM"].Value);
                            LonSeconds = double.Parse(matchDMS.Groups["latitudeS"].Value);
                        }

                        // no suffix or prefix was added so allow user to specify longitude first by checking for absolute value greater than 90
                        // fix for bug Bob Booth found in issue #42
                        if (!firstPrefix.Success && !firstSuffix.Success && !lastPrefix.Success && !lastSuffix.Success)
                        {
                            // switch the values if longitude was added first
                            if ((Math.Abs(LatDegrees) > 90.0) && (Math.Abs(LonDegrees) <= 90.0))
                            {
                                LatDegrees = int.Parse(matchDMS.Groups["longitudeD"].Value);
                                LatMinutes = int.Parse(matchDMS.Groups["longitudeM"].Value);
                                LatSeconds = double.Parse(matchDMS.Groups["longitudeS"].Value);
                                LonDegrees = int.Parse(matchDMS.Groups["latitudeD"].Value);
                                LonMinutes = int.Parse(matchDMS.Groups["latitudeM"].Value);
                                LonSeconds = double.Parse(matchDMS.Groups["latitudeS"].Value);
                            }
                            if ((Math.Abs(LatDegrees) > 90.0) && (Math.Abs(LonDegrees) > 90.0))
                            {
                                return(false);
                            }
                        }

                        if ((firstSuffix.Success || firstPrefix.Success) && (firstSuffix.Value.ToUpper().Equals("S") || firstPrefix.Value.ToUpper().Equals("S")) ||
                            (lastSuffix.Success || lastPrefix.Success) && (lastSuffix.Value.ToUpper().Equals("S") || lastPrefix.Value.ToUpper().Equals("S")))
                        {
                            LatDegrees = Math.Abs(LatDegrees) * -1;
                        }

                        if ((firstSuffix.Success || firstPrefix.Success) && (firstSuffix.Value.ToUpper().Equals("W") || firstPrefix.Value.ToUpper().Equals("W")) ||
                            (lastSuffix.Success || lastPrefix.Success) && (lastSuffix.Value.ToUpper().Equals("W") || lastPrefix.Value.ToUpper().Equals("W")))
                        {
                            LonDegrees = Math.Abs(LonDegrees) * -1;
                        }
                        if ((Math.Abs(LatDegrees) > 90.0) && (Math.Abs(LonDegrees) > 90.0))
                        {
                            return(false);
                        }
                        dms = new CoordinateDMS(LatDegrees, LatMinutes, LatSeconds, LonDegrees, LonMinutes, LonSeconds);
                    }
                    catch
                    {
                        return(false);
                    }

                    return(true);
                }
            }
            return(false);
        }