|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Decimal Degrees to DMSBelow is a funtion that converts a Lat or Lon coordinate (as a Double) to a string of Degrees, Minutes and Seconds. It's based on an MS Exmaple for VBA found here http://support.microsoft.com/?kbid=213449. Do you think this is this best way to go about it .NET, or could it be done more efficiently? ///// Private Function ConvertDegrees(ByVal DecimalDegrees As Double) As String Dim Degrees As Int32 = 0 Dim Minutes As Single = 0 Dim Seconds As Single = 0 Dim DMS As String = "" Degrees = Fix(DecimalDegrees) Minutes = (DecimalDegrees - Degrees) * 60 Seconds = (Minutes - Fix(Minutes)) * 60 DMS = System.Math.Abs(Degrees) & Chr(186) & _ " " & Format(System.Math.Abs(Fix(Minutes)), "00") & _ "' " & Format(System.Math.Abs(Seconds), "00.00") & Chr(34) Return DMS End Function ///// Thanks, Lance Well it depends in what context you use it.
You could perhaps remove some formatting if not needed. They are the most time eating (in relative terms). tommaso Lance ha scritto: Show quoteHide quote > Hi all, > > Below is a funtion that converts a Lat or Lon coordinate (as a Double) to a > string of Degrees, Minutes and Seconds. It's based on an MS Exmaple for VBA > found here http://support.microsoft.com/?kbid=213449. Do you think this is > this best way to go about it .NET, or could it be done more efficiently? > > ///// > Private Function ConvertDegrees(ByVal DecimalDegrees As Double) As String > Dim Degrees As Int32 = 0 > Dim Minutes As Single = 0 > Dim Seconds As Single = 0 > Dim DMS As String = "" > Degrees = Fix(DecimalDegrees) > Minutes = (DecimalDegrees - Degrees) * 60 > Seconds = (Minutes - Fix(Minutes)) * 60 > DMS = System.Math.Abs(Degrees) & Chr(186) & _ > " " & Format(System.Math.Abs(Fix(Minutes)), "00") & _ > "' " & Format(System.Math.Abs(Seconds), "00.00") & Chr(34) > Return DMS > End Function > ///// > > Thanks, > Lance Hi,
Efficiency wise, this should be OK. Unless you are doing this calculation hundreds of times per second... It shouldn't matter. Perhaps you could make it slightly faster (though perhaps not), but... Why bother? Dick -- Richard Grier, MVP Hard & Software Author of Visual Basic Programmer's Guide to Serial Communications, Fourth Edition, ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March 2006. See www.hardandsoftware.net for details and contact information. Thanks guys. I'll leave it as it is then.
Lance Show quoteHide quote "Dick Grier" <dick_grierNOSPAM@.msn.com> wrote in message news:uTsxqhvwGHA.3964@TK2MSFTNGP04.phx.gbl... > Hi, > > Efficiency wise, this should be OK. Unless you are doing this calculation > hundreds of times per second... It shouldn't matter. Perhaps you could > make it slightly faster (though perhaps not), but... Why bother? > > Dick > > -- > Richard Grier, MVP > Hard & Software > Author of Visual Basic Programmer's Guide to Serial Communications, Fourth > Edition, > ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March > 2006. > See www.hardandsoftware.net for details and contact information. > Lance,
When working with Latitude & Longitude I would consider defining a specific type that represents Latitude & Longitude. This type would then have a ToString method that formatted the value as expected. I would consider having a ToDouble & FromDouble conversions on this new type. I'll see if I can come up with a sample class later... -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> wrote in message news:OcEqE8uwGHA.5064@TK2MSFTNGP06.phx.gbl... | Hi all, | | Below is a funtion that converts a Lat or Lon coordinate (as a Double) to a | string of Degrees, Minutes and Seconds. It's based on an MS Exmaple for VBA | found here http://support.microsoft.com/?kbid=213449. Do you think this is | this best way to go about it .NET, or could it be done more efficiently? | | ///// | Private Function ConvertDegrees(ByVal DecimalDegrees As Double) As String | Dim Degrees As Int32 = 0 | Dim Minutes As Single = 0 | Dim Seconds As Single = 0 | Dim DMS As String = "" | Degrees = Fix(DecimalDegrees) | Minutes = (DecimalDegrees - Degrees) * 60 | Seconds = (Minutes - Fix(Minutes)) * 60 | DMS = System.Math.Abs(Degrees) & Chr(186) & _ | " " & Format(System.Math.Abs(Fix(Minutes)), "00") & _ | "' " & Format(System.Math.Abs(Seconds), "00.00") & Chr(34) | Return DMS | End Function | ///// | | Thanks, | Lance | | That sounds interesting. I'm looking forward to your example.
Lance Show quoteHide quote "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> wrote in message news:OjG62EHxGHA.4944@TK2MSFTNGP02.phx.gbl... > Lance, > When working with Latitude & Longitude I would consider defining a specific > type that represents Latitude & Longitude. > > This type would then have a ToString method that formatted the value as > expected. > > I would consider having a ToDouble & FromDouble conversions on this new > type. > > I'll see if I can come up with a sample class later... > > -- > Hope this helps > Jay B. Harlow [MVP - Outlook] > .NET Application Architect, Enthusiast, & Evangelist > T.S. Bradley - http://www.tsbradley.net > > > "Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> wrote in message > news:OcEqE8uwGHA.5064@TK2MSFTNGP06.phx.gbl... > | Hi all, > | > | Below is a funtion that converts a Lat or Lon coordinate (as a Double) to > a > | string of Degrees, Minutes and Seconds. It's based on an MS Exmaple for > VBA > | found here http://support.microsoft.com/?kbid=213449. Do you think this > is > | this best way to go about it .NET, or could it be done more efficiently? > | > | ///// > | Private Function ConvertDegrees(ByVal DecimalDegrees As Double) As String > | Dim Degrees As Int32 = 0 > | Dim Minutes As Single = 0 > | Dim Seconds As Single = 0 > | Dim DMS As String = "" > | Degrees = Fix(DecimalDegrees) > | Minutes = (DecimalDegrees - Degrees) * 60 > | Seconds = (Minutes - Fix(Minutes)) * 60 > | DMS = System.Math.Abs(Degrees) & Chr(186) & _ > | " " & Format(System.Math.Abs(Fix(Minutes)), "00") & _ > | "' " & Format(System.Math.Abs(Seconds), "00.00") & Chr(34) > | Return DMS > | End Function > | ///// > | > | Thanks, > | Lance > | > | > >
Late Binding Issue
VB Net and ADOX string reset? why? how? Need some advice? What is the .NET way? - Right("0" & Now.Month.ToString, 2) Redrawing a part of a control What to do when GetDeviceCaps doesn't? Concurrency violation: the DeleteCommand affected 0 records vb.net VB 2005 Visual Styles problem Web Service using stored procedures example? |
|||||||||||||||||||||||