void Units::LongitudeToDMS(Angle Longitude, int *dd, int *mm, int *ss, bool *east) { // if (Longitude is negative) -> Longitude is West otherwise East *east = (Longitude.sign() >= 0); unsigned value = (unsigned)(Longitude.magnitude_degrees() * 3600 + fixed_half); *ss = value % 60; value /= 60; *mm = value % 60; value /= 60; *dd = value; }
void Units::LatitudeToDMS(Angle Latitude, int *dd, int *mm, int *ss, bool *north) { // if (Latitude is negative) -> Latitude is South otherwise North *north = (Latitude.sign() >= 0); unsigned value = (unsigned)(Latitude.magnitude_degrees() * 3600 + fixed_half); *ss = value % 60; value /= 60; *mm = value % 60; value /= 60; *dd = value; }
bool Units::LatitudeToString(Angle Latitude, TCHAR *Buffer, size_t size) { (void)size; TCHAR EW[] = _T("SNN"); int dd, mm, ss; // Calculate Latitude sign int sign = Latitude.sign()+1; double mlat = Latitude.magnitude_degrees(); switch (CoordinateFormat) { case cfDDMMSS: // Calculate degrees dd = (int)mlat; // Calculate minutes mlat = (mlat - dd) * 60.0; mm = (int)(mlat); // Calculate seconds mlat = (mlat - mm) * 60.0; ss = (int)(mlat + 0.5); if (ss >= 60) { mm++; ss -= 60; } if (mm >= 60) { dd++; mm -= 60; } // Save the string to the Buffer _stprintf(Buffer, _T("%c%02d")_T(DEG)_T("%02d'%02d\""), EW[sign], dd, mm, ss); break; case cfDDMMSSss: // Calculate degrees dd = (int)mlat; // Calculate minutes mlat = (mlat - dd) * 60.0; mm = (int)(mlat); // Calculate seconds mlat = (mlat - mm) * 60.0; // Save the string to the Buffer _stprintf(Buffer, _T("%c%02d")_T(DEG)_T("%02d'%05.2f\""), EW[sign], dd, mm, mlat); break; case cfDDMMmmm: // Calculate degrees dd = (int)mlat; // Calculate minutes mlat = (mlat - dd) * 60.0; // Save the string to the Buffer _stprintf(Buffer, _T("%c%02d")_T(DEG)_T("%06.3f'"), EW[sign], dd, mlat); break; case cfDDdddd: // Save the string to the Buffer _stprintf(Buffer, _T("%c%07.4f")_T(DEG), EW[sign], mlat); break; default: return false; } return true; }