/** * set lat and lon * * @param strLatNS "N" or "S" * @param strLatDeg Degrees of Latitude * @param strLatMin Minutes of Latitude * @param strLatSec Seconds of Latitude * @param strLonEW "E" or "W" * @param strLonDeg Degrees of Longitude * @param strLonMin Minutes of Longitude * @param strLonSec Seconds of Longitude * @param format Format: DD, DMM, DMS */ public void set( String strLatNS, String strLatDeg, String strLatMin, String strLatSec, String strLonEW, String strLonDeg, String strLonMin, String strLonSec, int format) { switch (format) { case DD: this.latDec = Common.parseDouble(strLatDeg); this.lonDec = Common.parseDouble(strLonDeg); break; case DMM: this.latDec = Math.abs(Common.parseDouble(strLatDeg)) + Math.abs((Common.parseDouble(strLatMin) / 60)); this.lonDec = Math.abs(Common.parseDouble(strLonDeg)) + Math.abs((Common.parseDouble(strLonMin) / 60)); break; case DMS: this.latDec = Math.abs(Common.parseDouble(strLatDeg)) + Math.abs((Common.parseDouble(strLatMin) / 60)) + Math.abs((Common.parseDouble(strLatSec) / 3600)); this.lonDec = Math.abs(Common.parseDouble(strLonDeg)) + Math.abs((Common.parseDouble(strLonMin) / 60)) + Math.abs((Common.parseDouble(strLonSec) / 3600)); break; default: this.latDec = 91; this.lonDec = 361; } // makeValid(); // To avoid changing sign twice if we have something like W -34.2345 if (strLatNS.trim().equals("S") && this.latDec > 0) this.latDec *= -1; if (strLonEW.trim().equals("W") && this.lonDec > 0) this.lonDec *= -1; this.utmValid = false; }
/** * Returns the degrees or minutes or seconds (depending on parameter what) formatted as a string * To determine the degrees, we need to calculate the minutes (and seconds) just in case rounding * errors propagate. Equally we need to know the seconds to determine the minutes value. * * @param deg The coordinate in degrees * @param what 0=deg, 1=min, 2=sec * @param format DD,CW,DMM,DMS * @return */ private String getDMS(double deg, int what, int format) { deg = Math.abs(deg); long iDeg = (int) deg; double tmpMin, tmpSec; tmpMin = (deg - iDeg) * 60.0; switch (format) { case DD: return ""; case CW: case DMM: // Need to check if minutes would round up to 60 if (java.lang.Math.round(tmpMin * 1000.0) == 60000) { tmpMin = 0; iDeg++; } switch (what) { case 0: return MyLocale.formatLong(iDeg, "00"); case 1: return MyLocale.formatDouble(tmpMin, "00.000").replace(',', '.'); case 2: return ""; } case DMS: tmpSec = (tmpMin - (int) tmpMin) * 60.0; tmpMin = (int) tmpMin; // Check if seconds round up to 60 if (java.lang.Math.round(tmpSec * 10.0) == 600) { tmpSec = 0; tmpMin = tmpMin + 1.0; } // Check if minutes round up to 60 if (java.lang.Math.round(tmpMin) == 60) { tmpMin = 0; iDeg++; } switch (what) { case 0: return MyLocale.formatLong(iDeg, "00"); case 1: return MyLocale.formatDouble(tmpMin, "00"); case 2: return MyLocale.formatDouble(tmpSec, "00.0").replace(',', '.'); } } return ""; // Dummy to keep compiler happy }