Degrees, minutes and seconds to Decimal Degrees
-
Does anybody know how to do this with the information entered in this format? ##.#### I thought it might be in the Math class but isn't. Thanks for any help.
Darrall wrote:
I thought it might be in the Math class but isn't.
Wikipedia does http://en.wikipedia.org/wiki/Geographic_coordinate_conversion[^].
Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
-
Does anybody know how to do this with the information entered in this format? ##.#### I thought it might be in the Math class but isn't. Thanks for any help.
It's not a built-in function, but it's certainly not hard to do the arithmetic. Subtract the int part of ##.#### from the original. The remainder will be .####. Multiply that by 60 and again take the int part of the result - that's the minutes. Subtract the minutes from the result of the first multiplication, then multiply the result by 60 again. The result is the seconds, though there may be a decimal part in the result if the original datum wasn't an integral number of seconds. You can remove that if you don't want it by again taking only the int part of the result. I don't yet have enough experience with the language to suggest the syntax - for all I know, Convert.ToInt() might round, rather than truncate real values. If so you'll have to try another dodge. But it shouldn't be too difficult to manage. It's such a frequent problem, though, that I'm rather surprised that MS didn't include it as a stock function.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
-
It's not a built-in function, but it's certainly not hard to do the arithmetic. Subtract the int part of ##.#### from the original. The remainder will be .####. Multiply that by 60 and again take the int part of the result - that's the minutes. Subtract the minutes from the result of the first multiplication, then multiply the result by 60 again. The result is the seconds, though there may be a decimal part in the result if the original datum wasn't an integral number of seconds. You can remove that if you don't want it by again taking only the int part of the result. I don't yet have enough experience with the language to suggest the syntax - for all I know, Convert.ToInt() might round, rather than truncate real values. If so you'll have to try another dodge. But it shouldn't be too difficult to manage. It's such a frequent problem, though, that I'm rather surprised that MS didn't include it as a stock function.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
Thanks Roger. I know the conversion itself is simple if you're sitting there doing it on a calculator. It becomes fairly complicated using C# code though which is why I was surprised there wasn't already a Math function for it. They have sin, cos and tan which all work in angles and in the real world - surveying, mapping, navigation, etc. - angles come in degrees, minutes and seconds. I will pass my method along once I have finished it in case anybody else wants it. Thanks for your feedback.