/** * 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 }
/** * Get degrees of longitude in different formats * * @param format Format: DD, DMM, DMS, */ public String getLonDeg(int format) { switch (format) { case DD: return MyLocale.formatDouble(this.lonDec, "000.00000").replace(',', '.'); case CW: case DMM: case DMS: return (((lonDec < 100.0) && (lonDec > -100.0)) ? "0" : "") + getDMS(lonDec, 0, format); default: return ""; } }
/** * Get degrees of latitude in different formats * * @param format Format: DD, DMM, DMS, */ public String getLatDeg(int format) { switch (format) { case DD: return MyLocale.formatDouble(this.latDec, "00.00000").replace(',', '.'); case CW: case DMM: case DMS: return getDMS(latDec, 0, format); default: return ""; } }
/** * Returns the string representation of the CWPoint Formats DD, DMM (same as CW), DMS, UTM * * @return string representation of CWPoint */ public String toString(int format) { if (!isValid()) return MyLocale.getMsg(999, "not set"); switch (format) { case DD: return getNSLetter() + " " + STRreplace.replace(getLatDeg(format), "-", "") + "° " + getEWLetter() + " " + STRreplace.replace(getLonDeg(format), "-", "") + "°"; case CW: format = DMM; return getNSLetter() + " " + getLatDeg(format) + "° " + getLatMin(format) + " " + getEWLetter() + " " + getLonDeg(format) + "° " + getLonMin(format); case DMM: return getNSLetter() + " " + getLatDeg(format) + "° " + getLatMin(format) + " " + getEWLetter() + " " + getLonDeg(format) + "° " + getLonMin(format); case DMS: return getNSLetter() + " " + getLatDeg(format) + "° " + getLatMin(format) + "\' " + getLatSec(format) + "\" " + getEWLetter() + " " + getLonDeg(format) + "° " + getLonMin(format) + "\' " + getLonSec(format) + "\""; case UTM: return getUTMZone() + " E " + getUTMEasting() + " N " + getUTMNorthing(); case LON_LAT: return Common.DoubleToString(lonDec, 8) + "," + Common.DoubleToString(latDec, 8); case LAT_LON: return Common.DoubleToString(latDec, 8) + "," + Common.DoubleToString(lonDec, 8); case GK: return getGermanGkCoordinates(); default: return "Unknown Format: " + format; } }