将一个浮点数转换为 多少度,多少分,多少秒的格式
const
CsAngleDegree = '°';
CsAngleMinute = '′';
CsAngleSecond = '″';
CSCoordShortTitle: array[boolean, boolean] of string = (('W', 'E'), ('S', 'N'));
function AngleXToStr(Value: Double; LeadZero: Boolean): string;
var
Plus: Boolean;
sFormat: string;
begin
Plus := Value >= 0;
Value := Abs(Value);
if LeadZero then sFormat := '%s%0.3d%s' else sFormat := '%s%d%s';
Result := Format(sFormat, [CSCoordShortTitle[False, Plus], Trunc(Value), CsAngleDegree]);
Value := Abs(Value - Int(Value)) * 60.0;
if LeadZero then sFormat := '%s%0.2d%s' else sFormat := '%s%d%s';
Result := Format(sFormat, [Result, Trunc(Value), CsAngleMinute]);
Value := (Value - Int(Value)) * 60.0;
if LeadZero then sFormat := '%s%5.2f%s' else sFormat := '%s%0.2f%s';
Result := Format(sFormat, [Result, Value, CsAngleSecond]);
end;
function AngleYToStr(Value: Double; LeadZero: Boolean): string;
var
Plus: Boolean;
sFormat: string;
begin
Plus := Value >= 0;
Value := Abs(Value);
if LeadZero then sFormat := '%s%0.2d%s' else sFormat := '%s%d%s';
Result := Format(sFormat, [CSCoordShortTitle[True, Plus], Trunc(Value), CsAngleDegree]);
Value := Abs(Value - Int(Value)) * 60.0;
if LeadZero then sFormat := '%s%0.2d%s' else sFormat := '%s%d%s';
Result := Format(sFormat, [Result, Trunc(Value), CsAngleMinute]);
Value := (Value - Int(Value)) * 60.0;
if LeadZero then sFormat := '%s%5.2f%s' else sFormat := '%s%0.2f%s';
Result := Format(sFormat, [Result, Value, CsAngleSecond]);
end;
DMS经纬度转化成浮点数:
R = D + M/60 + S/3600