public String convertLatLonToUTM(double latitude, double longitude) { validate(latitude, longitude); String UTM = ""; setVariables(latitude, longitude); String longZone = getLongZone(longitude); LatZones latZones = new LatZones(); String latZone = latZones.getLatZone(latitude); double _easting = getEasting(); double _northing = getNorthing(latitude); UTM = longZone + " " + latZone + " " + ((int)_easting) + " " + ((int)_northing); // UTM = longZone + " " + latZone + " " + decimalFormat.format(_easting) + // " "+ decimalFormat.format(_northing); return(UTM); }
public double[] convertMGRUTMToLatLong(string mgrutm) { double[] latlon = { 0.0, 0.0 }; // 02CNR0634657742 int zone = int.Parse(mgrutm.Substring(0, 2)); string latZone = mgrutm.Substring(2, 3); string digraph1 = mgrutm.Substring(3, 4); string digraph2 = mgrutm.Substring(4, 5); easting = double.Parse(mgrutm.Substring(5, 10)); northing = double.Parse(mgrutm.Substring(10, 15)); LatZones lz = new LatZones(); double latZoneDegree = lz.getLatZoneDegree(latZone); double a1 = latZoneDegree * 40000000 / 360.0; double a2 = 2000000 * Math.Floor(a1 / 2000000.0); Digraphs digraphs = new Digraphs(); double digraph2Index = digraphs.getDigraph2Index(digraph2); double startindexEquator = 1; if ((1 + zone % 2) == 1) { startindexEquator = 6; } double a3 = a2 + (digraph2Index - startindexEquator) * 100000; if (a3 <= 0) { a3 = 10000000 + a3; } northing = a3 + northing; zoneCM = -183 + 6 * zone; double digraph1Index = digraphs.getDigraph1Index(digraph1); int a5 = 1 + zone % 3; double[] a6 = { 16, 0, 8 }; double a7 = 100000 * (digraph1Index - a6[a5 - 1]); easting = easting + a7; setVariables(); double latitude = 0; latitude = 180 * (phi1 - fact1 * (fact2 + fact3 + fact4)) / Math.PI; if (latZoneDegree < 0) { latitude = 90 - latitude; } double d = _a2 * 180 / Math.PI; double longitude = zoneCM - d; if (getHemisphere(latZone).Equals("S")) { latitude = -latitude; } latlon[0] = latitude; latlon[1] = longitude; return latlon; }
public string convertLatLonToUTM(double latitude, double longitude) { validate(latitude, longitude); string UTM = ""; setVariables(latitude, longitude); string longZone = getLongZone(longitude); LatZones latZones = new LatZones(); string latZone = latZones.getLatZone(latitude); double _easting = getEasting(); double _northing = getNorthing(latitude); UTM = longZone + " " + latZone + " " + ((int)_easting) + " " + ((int)_northing); // UTM = longZone + " " + latZone + " " + decimalFormat.format(_easting) + // " "+ decimalFormat.format(_northing); return UTM; }
public string convertLatLonToMGRUTM(double latitude, double longitude) { validate(latitude, longitude); String mgrUTM = ""; setVariables(latitude, longitude); string longZone = getLongZone(longitude); LatZones latZones = new LatZones(); string latZone = latZones.getLatZone(latitude); double _easting = getEasting(); double _northing = getNorthing(latitude); Digraphs digraphs = new Digraphs(); string digraph1 = digraphs.getDigraph1(int.Parse(longZone), _easting); string digraph2 = digraphs.getDigraph2(int.Parse(longZone), _northing); string easting = ((int)_easting) + ""; if (easting.Length < 5) { easting = "00000" + easting; } easting = easting.Substring(easting.Length - 5); string northing; northing = ((int)_northing) + ""; if (northing.Length < 5) { northing = "0000" + northing; } northing = northing.Substring(northing.Length - 5); mgrUTM = longZone + latZone + digraph1 + digraph2 + easting + northing; return mgrUTM; }