Sexagesimal Conversions in .Net
Posted by Dan Rigsby on April 30th, 2008
No, that is not a dirty word, and yes, it is fun to say. [sek-suh-jes-uh-muhl]
Sexagesimal is a base-60 number system much like our own base-10 decimal system. Throughout history different cultures have chosen different base numbering systems based on things they considered common or sacred. Many people today recognize numbers as always being base-10, and it can be quite difficult to explain a different numbering system to a child. Those of us in computer science are quite use to a base-2 (binary) system. Some of the more common historic number systems are:
- Base-5 (quinary): This system has been popular because five can easily be represented by the five fingers on one hand
- Base-8 (octal): Some cultures used only their fingers to count and used the thumbs as place holders. While other cultures, such as the Yuki Native American tribe of Northern California , counted the spaces between the fingers. The Yuki actually started counting with 0 as well (much like C based languages). So the numbers 0-7 were counted on their fingers.
- Base-10 (decimal): We are all familiar with the base-10 system which is almost universally used around the world. Historical this is based on the fact that humans have ten fingers on which to count.
- Base-12 (duodecimal): This system is based on the knuckles of the four fingers. Each finger has 3 knuckles and the thumb is used as the place holder. Twelve is also an important unit in British measurement such as 12 inches in a foot, 12 pennies to a shilling, 12 numbers used in our time units, etc.
- Base-20 (vigesimal): The base-20 system originates from the combination of ten fingers and ten toes on which to count. This is most widely known to be used by the Mayan civilization.
- Base-60 (sexigesimal): The base-60 system dates back to the Sumerians and the early cultures of Mesopotamia. It’s hard to say where this system originated from, but common belief is that it is a combination of the base-10 and base-12 systems.
So why is the base-60 system still important to us today? Well for one, there are 60 seconds in a minute and 60 minutes in an hour. This measurement one of the Sumerian’s lasting impressions today. Their calendar and type systems have been adopted and modified throughout the Asia and Europe. We can blame the Sumerian’s for not having enough time in the day.
Another popular use for the base-60 system is in angular measure in our spherical coordinate system of the Earth. A degree is divided into 60 minutes and a minute is divided into 60 seconds. Our system of Latitudes and Longitudes is expressed in these terms. With the popularity of geo-spatial and mapping tools such as Google Maps and Microsoft Live Maps, it has become important to be able to convert from degrees/minutes/seconds into a decimal notation and vice versa.
Example:
(49°30′02"N, 123°30′30")
49 degrees, 30 minutes, and 2 seconds by 123 degrees, 30 minutes, and 30 seconds
Below is a utilities class that I originally wrote for an astronomical observatory simulation application called StellarResults (which is available on codeplex). This program would simulate observatories around the world and what astronomical objects they could see at a give time of day. I soon realized that I needed to push this library down to a more basic level so that I could use it for other geo-spatial calculations such as working with geo-coded locations, or entering locations into a database. Libraries like this will also be useful when working with the new spatial database features in Microsoft SQL Server 2008.
public static class GISUtilities { #region Sexagesimal /// <summary> /// Converts from degrees, minues, seconds to a double. /// </summary> /// <param name="degrees">The degrees.</param> /// <param name="minutes">The minutes.</param> /// <param name="seconds">The seconds.</param> /// <returns></returns> public static double ConvertSexagesimalToDouble( int degrees, int minutes, int seconds) { return ((double)degrees % 360) + ((double)minutes / 60) + ((double)seconds / 3600); } /// <summary> /// Converts from degrees, minues, seconds to a string. /// </summary> /// <param name="degrees">The degrees.</param> /// <param name="minutes">The minutes.</param> /// <param name="seconds">The seconds.</param> /// <returns></returns> public static string ConvertSexagesimalToString( int degrees, int minutes, int seconds) { return String.Format( "{0}° {1}’ {2}”", degrees.ToString(), minutes.ToString(), seconds.ToString()); } /// <summary> /// Converts from a double to degrees, minues, seconds. /// </summary> /// <param name="value">The value to convert.</param> /// <param name="degrees">The degrees.</param> /// <param name="minutes">The minutes.</param> /// <param name="seconds">The seconds.</param> public static void ConvertDoubleToSexagesimal( double value, out int degrees, out int minutes, out int seconds) { degrees = (int)value; minutes = (int)((value - degrees) * 60); seconds = (int)((value - degrees - (minutes / 60)) * 3600); } #endregion Sexagesimal #region HMS /// <summary> /// Converts from hours, minues, seconds to a double. /// </summary> /// <param name="hours">The hours.</param> /// <param name="minutes">The minutes.</param> /// <param name="seconds">The seconds.</param> /// <returns></returns> public static double ConvertHMSToDouble( int hours, int minutes, int seconds) { return ((double)hours % 360) * 15 + ((double)minutes / 60) * 15 + ((double)seconds / 3600) * 15; } /// <summary> /// Converts from hours, minues, seconds to a string. /// </summary> /// <param name="hours">The hours.</param> /// <param name="minutes">The minutes.</param> /// <param name="seconds">The seconds.</param> /// <returns></returns> public static string ConvertHMSToString( int hours, int minutes, int seconds) { return String.Format( "{0}h {1}m {2}s", hours.ToString(), minutes.ToString(), seconds.ToString()); } /// <summary> /// Converts from a double to hours, minues, seconds. /// </summary> /// <param name="value">The value to convert.</param> /// <param name="hours">The hours.</param> /// <param name="minutes">The minutes.</param> /// <param name="seconds">The seconds.</param> public static void ConvertDoubleToHMS( double value, out int hours, out int minutes, out int seconds) { double totalseconds = value / 15 * 3600; hours = (int)Math.Truncate(totalseconds / 3600); minutes = (int)Math.Truncate((totalseconds - hours * 3600) / 60); seconds = (int)Math.Truncate(totalseconds - (hours * 3600) - (minutes * 60)); } #endregion HMS }
So a conversion from Latitude or Longitude to a double would look something like this:
double latitude = GISUtilities.ConvertSexagesimalToDouble(100, 34, 20);










May 1st, 2008 at 2:19 am
[...] Sexagesimal Conversions in .Net - Dan Rigsby looks at the importance of Sexagesimal - a base 60 number system- and how it relates to time (60 minutes in an hour) and more significantly Longitude and Latitude. [...]
May 5th, 2008 at 3:25 pm
[...] Sexagesimal Conversions in .Net [...]
May 5th, 2008 at 3:26 pm
[...] Sexagesimal Conversions in .Net [...]