public override bool Equals(object obj) { if (obj is DegreeMinutes) { DegreeMinutes other = obj as DegreeMinutes; if ((other.Degrees == Degrees) && (Math.Round(other.Minutes, 5) == Math.Round(Minutes, 5)) && (other.IsNegative == m_isNegative)) { return(true); } } return(false); }
public static string getLonStringCN(DegreeMinutes lon) { String co_ordinate = ""; if (lon.GetDecimalDegrees() > 0) { co_ordinate += String.Format(" E {0}° {1}", lon.Degrees, lon.Minutes.ToString("0.000", CultureInfo.InvariantCulture)); } else { co_ordinate += String.Format(" W {0}° {1}", lon.Degrees * -1, lon.Minutes.ToString("0.000", CultureInfo.InvariantCulture)); } return(co_ordinate); }
public static string getLatString(DegreeMinutes lat) { String co_ordinate = ""; if (lat.GetDecimalDegrees() > 0) { co_ordinate += String.Format(Catalog.GetString("N {0}° {1}"), lat.Degrees, lat.Minutes.ToString("0.000", CultureInfo.InvariantCulture)); } else { co_ordinate += String.Format(Catalog.GetString("S {0}° {1}"), lat.Degrees * -1, lat.Minutes.ToString("0.000", CultureInfo.InvariantCulture)); } return(co_ordinate); }
public static DegreeMinutes[] ParseCoordString(String val) { DegreeMinutes[] coord = new DegreeMinutes[2]; if (Regex.IsMatch(val, DEC_DEGREES_1)) { Match match = Regex.Match(val, DEC_DEGREES_1); bool signLat = match.Groups[1].Value == "S"; double absLat = double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture); System.Console.WriteLine(absLat.ToString()); System.Console.WriteLine(match.Groups[2].Value); coord[0] = new DegreeMinutes(signLat ? -absLat: absLat); bool signLon = match.Groups[3].Value == "W"; double absLon = double.Parse(match.Groups[4].Value, CultureInfo.InvariantCulture); coord[1] = new DegreeMinutes(signLon ? -absLon : absLon); } else if (Regex.IsMatch(val, DEGREE_MINUTES)) { Match match = Regex.Match(val, DEGREE_MINUTES); int degLat = int.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture); if (match.Groups[1].Value == "S") degLat = degLat * -1; double minLat = double.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture); DegreeMinutes lat = new DegreeMinutes(degLat, minLat); int degLon = int.Parse(match.Groups[5].Value, CultureInfo.InvariantCulture); if (match.Groups[4].Value == "W") degLon = degLon * -1; double minLon = double.Parse(match.Groups[6].Value, CultureInfo.InvariantCulture); DegreeMinutes lon = new DegreeMinutes(degLon, minLon); coord[0] = lat; coord[1] = lon; } else if (Regex.IsMatch(val, DEC_DEGREES_2)) { Match match = Regex.Match(val, DEC_DEGREES_2); coord[0] = new DegreeMinutes(Double.Parse(match.Groups[1].Value)); coord[1] = new DegreeMinutes(Double.Parse(match.Groups[2].Value)); } else if (Regex.IsMatch(val, DMS)) { throw new Exception("NOT_YET_IMPLEMENTED"); } else { System.Console.WriteLine(val); throw new Exception(Catalog.GetString("Unknown Coordinate Format")); } return coord; /* bool signLat = re1.cap(1) == "S"; int degLat = re1.cap(2).toInt(); float minLat = re1.cap(3).toDouble(); GPS_Math_DegMin_To_Deg(signLat, degLat, minLat, lat); bool signLon = re1.cap(4) == "W"; int degLon = re1.cap(5).toInt(); float minLon = re1.cap(6).toDouble(); GPS_Math_DegMin_To_Deg(signLon, degLon, minLon, lon); } DegreeMinutes val = new DegreeMinutes(0.0); return val; /* * bool GPS_Math_Str_To_Deg(const QString& str, float& lon, float& lat, bool silent) { QRegExp re1("^\\s*([N|S]){1}\\W*([0-9]+)\\W*([0-9]+\\.[0-9]+)\\s+([E|W]){1}\\W*([0-9]+)\\W*([0-9]+\\.[0-9]+)\\s*$"); QRegExp re2("^\\s*([N|S]){1}\\s*([0-9]+\\.[0-9]+)\\W*\\s+([E|W]){1}\\s*([0-9]+\\.[0-9]+)\\W*\\s*$"); QRegExp re3("^\\s*([-0-9]+\\.[0-9]+)\\s+([-0-9]+\\.[0-9]+)\\s*$"); QRegExp re4("^\\s*([N|S]){1}\\s*([0-9]+)\\W*([0-9]+)\\W*([0-9]+)\\W*([E|W]){1}\\W*([0-9]+)\\W*([0-9]+)\\W*([0-9]+)\\W*\\s*$"); if(re2.exactMatch(str)) { bool signLat = re2.cap(1) == "S"; float absLat = re2.cap(2).toDouble(); lat = signLat ? -absLat : absLat; bool signLon = re2.cap(3) == "W"; float absLon = re2.cap(4).toDouble(); lon = signLon ? -absLon : absLon; } else if(re1.exactMatch(str)) { bool signLat = re1.cap(1) == "S"; int degLat = re1.cap(2).toInt(); float minLat = re1.cap(3).toDouble(); GPS_Math_DegMin_To_Deg(signLat, degLat, minLat, lat); bool signLon = re1.cap(4) == "W"; int degLon = re1.cap(5).toInt(); float minLon = re1.cap(6).toDouble(); GPS_Math_DegMin_To_Deg(signLon, degLon, minLon, lon); } else if(re3.exactMatch(str)) { lat = re3.cap(1).toDouble(); lon = re3.cap(2).toDouble(); } else if(re4.exactMatch(str)) { bool signLat = re4.cap(1) == "S"; int degLat = re4.cap(2).toInt(); int minLat = re4.cap(3).toInt(); int secLat = re4.cap(4).toInt(); GPS_Math_DegMinSec_To_Deg(signLat, degLat, minLat, secLat, lat); bool signLon = re4.cap(5) == "W"; int degLon = re4.cap(6).toInt(); int minLon = re4.cap(7).toInt(); int secLon = re4.cap(8).toInt(); GPS_Math_DegMinSec_To_Deg(signLon, degLon, minLon, secLon, lon); } else { if(!silent) QMessageBox::warning(0,QObject::tr("Error"),QObject::tr("Bad position format. Must be: \"[N|S] ddd mm.sss [W|E] ddd mm.sss\" or \"[N|S] ddd.ddd [W|E] ddd.ddd\""),QMessageBox::Ok,QMessageBox::NoButton); return false; } if(fabs(lon) > 180.0 || fabs(lat) > 90.0) { if(!silent) QMessageBox::warning(0,QObject::tr("Error"),QObject::tr("Position values out of bounds. "),QMessageBox::Ok,QMessageBox::NoButton); return false; } return true; }*/ }
public static string getLonStringCN(DegreeMinutes lon) { String co_ordinate = ""; if (lon.Degrees > 0) co_ordinate += String.Format(" E {0}° {1}", lon.Degrees, lon.Minutes.ToString("0.000", CultureInfo.InvariantCulture)); else co_ordinate += String.Format(" W {0}° {1}", lon.Degrees *-1 , lon.Minutes.ToString("0.000", CultureInfo.InvariantCulture)); return co_ordinate; }
public static string getLatStringCN(DegreeMinutes lat) { String co_ordinate = ""; if (lat.Degrees > 0) co_ordinate += String.Format("N {0}° {1}", lat.Degrees,lat.Minutes.ToString("0.000", CultureInfo.InvariantCulture)); else co_ordinate += String.Format("S {0}° {1}", lat.Degrees * -1, lat.Minutes.ToString("0.000", CultureInfo.InvariantCulture)); return co_ordinate; }
public static string getCoordStringCN(DegreeMinutes lat, DegreeMinutes lon) { return getLatStringCN(lat) + " " + getLonStringCN(lon); }
public static DegreeMinutes[] ParseCoordString(String val) { DegreeMinutes[] coord = new DegreeMinutes[2]; if (Regex.IsMatch(val, DEC_DEGREES_1)) { Match match = Regex.Match(val, DEC_DEGREES_1); bool signLat = match.Groups[1].Value == "S"; double absLat = double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture); System.Console.WriteLine(absLat.ToString()); System.Console.WriteLine(match.Groups[2].Value); coord[0] = new DegreeMinutes(signLat ? -absLat: absLat); bool signLon = match.Groups[3].Value == "W"; double absLon = double.Parse(match.Groups[4].Value, CultureInfo.InvariantCulture); coord[1] = new DegreeMinutes(signLon ? -absLon : absLon); } else if (Regex.IsMatch(val, DEGREE_MINUTES)) { Match match = Regex.Match(val, DEGREE_MINUTES); int degLat = int.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture); bool isNeg = false; if (match.Groups[1].Value == "S") { degLat = degLat * -1; isNeg = true; } double minLat = double.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture); DegreeMinutes lat = new DegreeMinutes(degLat, minLat, isNeg); isNeg = false; int degLon = int.Parse(match.Groups[5].Value, CultureInfo.InvariantCulture); if (match.Groups[4].Value == "W") { degLon = degLon * -1; isNeg = true; } double minLon = double.Parse(match.Groups[6].Value, CultureInfo.InvariantCulture); DegreeMinutes lon = new DegreeMinutes(degLon, minLon, isNeg); coord[0] = lat; coord[1] = lon; } else if (Regex.IsMatch(val, DEC_DEGREES_2)) { Match match = Regex.Match(val, DEC_DEGREES_2); coord[0] = new DegreeMinutes(Double.Parse(match.Groups[1].Value)); coord[1] = new DegreeMinutes(Double.Parse(match.Groups[2].Value)); } else if (Regex.IsMatch(val, DMS)) { throw new Exception("NOT_YET_IMPLEMENTED"); } else { System.Console.WriteLine(val); throw new Exception(Catalog.GetString("Unknown Coordinate Format")); } return(coord); /* bool signLat = re1.cap(1) == "S"; * int degLat = re1.cap(2).toInt(); * float minLat = re1.cap(3).toDouble(); * * GPS_Math_DegMin_To_Deg(signLat, degLat, minLat, lat); * * bool signLon = re1.cap(4) == "W"; * int degLon = re1.cap(5).toInt(); * float minLon = re1.cap(6).toDouble(); * * GPS_Math_DegMin_To_Deg(signLon, degLon, minLon, lon); * } * * * DegreeMinutes val = new DegreeMinutes(0.0); * return val; * /* * bool GPS_Math_Str_To_Deg(const QString& str, float& lon, float& lat, bool silent) * { * QRegExp re1("^\\s*([N|S]){1}\\W*([0-9]+)\\W*([0-9]+\\.[0-9]+)\\s+([E|W]){1}\\W*([0-9]+)\\W*([0-9]+\\.[0-9]+)\\s*$"); * * QRegExp re2("^\\s*([N|S]){1}\\s*([0-9]+\\.[0-9]+)\\W*\\s+([E|W]){1}\\s*([0-9]+\\.[0-9]+)\\W*\\s*$"); * * QRegExp re3("^\\s*([-0-9]+\\.[0-9]+)\\s+([-0-9]+\\.[0-9]+)\\s*$"); * * QRegExp re4("^\\s*([N|S]){1}\\s*([0-9]+)\\W*([0-9]+)\\W*([0-9]+)\\W*([E|W]){1}\\W*([0-9]+)\\W*([0-9]+)\\W*([0-9]+)\\W*\\s*$"); * * if(re2.exactMatch(str)) * { * bool signLat = re2.cap(1) == "S"; * float absLat = re2.cap(2).toDouble(); * lat = signLat ? -absLat : absLat; * * bool signLon = re2.cap(3) == "W"; * float absLon = re2.cap(4).toDouble(); * lon = signLon ? -absLon : absLon; * } * else if(re1.exactMatch(str)) * { * * bool signLat = re1.cap(1) == "S"; * int degLat = re1.cap(2).toInt(); * float minLat = re1.cap(3).toDouble(); * * GPS_Math_DegMin_To_Deg(signLat, degLat, minLat, lat); * * bool signLon = re1.cap(4) == "W"; * int degLon = re1.cap(5).toInt(); * float minLon = re1.cap(6).toDouble(); * * GPS_Math_DegMin_To_Deg(signLon, degLon, minLon, lon); * } * else if(re3.exactMatch(str)) * { * lat = re3.cap(1).toDouble(); * lon = re3.cap(2).toDouble(); * } * else if(re4.exactMatch(str)) * { * bool signLat = re4.cap(1) == "S"; * int degLat = re4.cap(2).toInt(); * int minLat = re4.cap(3).toInt(); * int secLat = re4.cap(4).toInt(); * * GPS_Math_DegMinSec_To_Deg(signLat, degLat, minLat, secLat, lat); * * bool signLon = re4.cap(5) == "W"; * int degLon = re4.cap(6).toInt(); * int minLon = re4.cap(7).toInt(); * int secLon = re4.cap(8).toInt(); * * GPS_Math_DegMinSec_To_Deg(signLon, degLon, minLon, secLon, lon); * * * } * else * { * if(!silent) QMessageBox::warning(0,QObject::tr("Error"),QObject::tr("Bad position format. Must be: \"[N|S] ddd mm.sss [W|E] ddd mm.sss\" or \"[N|S] ddd.ddd [W|E] ddd.ddd\""),QMessageBox::Ok,QMessageBox::NoButton); * return false; * } * * if(fabs(lon) > 180.0 || fabs(lat) > 90.0) * { * if(!silent) QMessageBox::warning(0,QObject::tr("Error"),QObject::tr("Position values out of bounds. "),QMessageBox::Ok,QMessageBox::NoButton); * return false; * } * * return true; * }*/ }
public static string getCoordStringCN(DegreeMinutes lat, DegreeMinutes lon) { return(getLatStringCN(lat) + " " + getLonStringCN(lon)); }