![]() |
Umwandlung geograf. Koord. DD.DDDDD -> N/S DD° MM.MMM'
Mit folgenden Funktionen lassen sich geografische Koordinaten vom Typ Float in lesbares String-Format (N 53° 12.345' und zuück konvertieren.
function SingleCoordString(value: Double; IsLatitude: Boolean): String; // Umwandeln eines Koordinatenwertes DD.DDDDD in X DD° MM.MMM' // X kann N/S/W/E sein. function CoordStrToFloat(sWert:String):Double; // Umwandeln eines Koordinatenwertes X DD° MM.MMM' in DD.DDDDD
Delphi-Quellcode:
function SingleCoordString(value: Double; IsLatitude: Boolean): String;
var sDeg, sMin: String; begin DegToDegMinStr(Abs(value), sDeg, sMin); case IsLatitude of false: if value < 0 then Result := 'W ' + Right(sDeg,3,'0') + '° ' + Right(sMin,6,'0')+'''' else Result := 'E ' + Right(sDeg,3,'0') + '° ' + Right(sMin,6,'0')+''''; true : if value < 0 then Result := 'S ' + Right(sDeg,2,'0') + '° ' + Right(sMin,6,'0')+'''' else Result := 'N ' + Right(sDeg,2,'0') + '° ' + Right(sMin,6,'0')+''''; end; end; function DegMinStrToDeg(sDeg, sMin: String; Direction: Char): Double; var Sign: Double; dDeg: Double; dMin: Double; bkDecSep : char; begin ReplaceInString(sMin, ',', '.'); bkDecSep := DecimalSeparator; DecimalSeparator := '.'; if Direction in ['W','S'] then Sign := -1.0 else Sign := 1.0; try dDeg := StrToFloat(sDeg); dMin := StrToFloat(sMin); result := (dDeg + dMin / 60) * Sign; except result := -999; end; DecimalSeparator := bkDecSep; end; function ReplaceInString(var sSource: String; sSearch, sReplace: String): Integer; var nRes: Integer; apos: Integer; sRest: String; begin nRes := 0; repeat apos := Pos(sSearch, sSource); if (apos > 0) then begin Inc(nRes); sRest := Copy(sSource, apos + Length(sSearch), Length(sSource) - apos - Length(sSearch) + 1); sSource := Copy(sSource, 1, apos - 1) + sReplace + sRest; end; until (apos < 1) or (nRes > 9999); result := nRes; end; FUNCTION Right(Instring : String; max : Byte; Filler : Char) : String; { Diese Funktion füllt Instring mit max Fillchar rechtsbündig auf } VAR Rzeile : String; i : Integer; BEGIN {--- OF FUNCTION Right } RZeile := ''; InString := Trim(InString); i := (max - Length(Instring)); If i > 0 Then For i := 1 To (max - Length(Instring)) Do Rzeile := Rzeile + Filler; Right := Rzeile + Instring; END; {--- OF FUNCTION Right } function CoordStrToFloat(sWert:String):Double; // Umwandeln eines Koordinatenwertes X DD° MM.MMM' in DD.DDDDD var HR, sDeg, sMin : String; begin HR := Wort(sWert, 1); sDeg := Wort(sWert, 2); sMin := Wort(sWert, 3); ReplaceInString(sDeg, '°',''); ReplaceInString(sMin, '''',''); Result := DegMinStrToDeg(sDeg,sMin, HR[1]); end; function DegMinStrToDeg(sDeg, sMin: String; Direction: Char): Double; var Sign: Double; dDeg: Double; dMin: Double; bkDecSep : char; begin ReplaceInString(sMin, ',', '.'); bkDecSep := DecimalSeparator; DecimalSeparator := '.'; if Direction in ['W','S'] then Sign := -1.0 else Sign := 1.0; try dDeg := StrToFloat(sDeg); dMin := StrToFloat(sMin); result := (dDeg + dMin / 60) * Sign; except result := -999; end; DecimalSeparator := bkDecSep; end; Happy Navigating :zwinker: Edit: function SingleCoordString hinzugefügt |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:55 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz