/// <summary> /// Converts UTM coordinate to Signed Degree Lat/Long /// </summary> /// <param name="utm">utm</param> /// <returns>Coordinate</returns> /// <example> /// The following example creates (converts to) a signed degree lat long based on a UTM object. /// <code> /// UniversalTransverseMercator utm = new UniversalTransverseMercator("T", 32, 233434, 234234); /// double[] signed = UniversalTransverseMercator.ConvertUTMtoSignedDegree(utm); /// Coordinate c = new Coordinate(signed[0], signed[1], new EagerLoad(false)); /// Console.WriteLine(c); //N 2º 7' 2.332" E 6º 36' 12.653" /// </code> /// </example> public static double[] ConvertUTMtoSignedDegree(UniversalTransverseMercator utm) { bool southhemi = false; Regex upsCheck = new Regex("[AaBbYyZz]"); if (upsCheck.IsMatch(utm.latZone)) { Coordinate c = UPS.UPS_To_Geodetic(utm, new EagerLoad(false)); return(new double[] { c.Latitude.ToDouble(), c.Longitude.ToDouble() }); } if (utm.latZone == "A" || utm.latZone == "B" || utm.latZone == "C" || utm.latZone == "D" || utm.latZone == "E" || utm.latZone == "F" || utm.latZone == "G" || utm.latZone == "H" || utm.latZone == "J" || utm.latZone == "K" || utm.latZone == "L" || utm.latZone == "M") { southhemi = true; } double cmeridian; double x = utm.Easting - 500000.0; double UTMScaleFactor = 0.9996; x /= UTMScaleFactor; /* If in southern hemisphere, adjust y accordingly. */ double y = utm.Northing; if (southhemi) { y -= 10000000.0; } y /= UTMScaleFactor; cmeridian = UTMCentralMeridian(utm.LongZone); double[] signed = UTMtoSigned(x, y, cmeridian, utm.equatorial_radius, utm.inverse_flattening); return(signed); }
/// <summary> /// Converts UTM coordinate to Lat/Long /// </summary> /// <param name="utm">utm</param> /// <param name="eagerLoad">EagerLoad</param> /// <returns>Coordinate</returns> /// <example> /// The following example creates (converts to) a geodetic Coordinate object based on a UTM object. /// Performance is maximized by turning off EagerLoading. /// <code> /// EagerLoad el = new EagerLoad(false); /// UniversalTransverseMercator utm = new UniversalTransverseMercator("T", 32, 233434, 234234); /// Coordinate c = UniversalTransverseMercator.ConvertUTMtoLatLong(utm, el); /// Console.WriteLine(c); //N 2º 7' 2.332" E 6º 36' 12.653" /// </code> /// </example> public static Coordinate ConvertUTMtoLatLong(UniversalTransverseMercator utm, EagerLoad eagerLoad) { bool southhemi = false; Regex upsCheck = new Regex("[AaBbYyZz]"); if (upsCheck.IsMatch(utm.latZone)) { return(UPS.UPS_To_Geodetic(utm, eagerLoad)); } Regex regex = new Regex("[CcDdEeFfGgHhJjKkLlMm]"); if (regex.IsMatch(utm.latZone)) { southhemi = true; } double cmeridian; double x = utm.Easting - 500000.0; double UTMScaleFactor = 0.9996; x /= UTMScaleFactor; /* If in southern hemisphere, adjust y accordingly. */ double y = utm.Northing; if (southhemi) { y -= 10000000.0; } y /= UTMScaleFactor; cmeridian = UTMCentralMeridian(utm.LongZone); Coordinate c = UTMtoLatLong(x, y, cmeridian, utm.equatorial_radius, utm.inverse_flattening, eagerLoad); return(c); }