Example #1
0
        public static GeoAngle FromDouble(double angleInDegrees)
        {
            //ensure the value will fall within the primary range [-180.0..+180.0]
            while (angleInDegrees < -180.0)
                angleInDegrees += 360.0;

            while (angleInDegrees > 180.0)
                angleInDegrees -= 360.0;

            var result = new GeoAngle();

            //switch the value to positive
            result.IsNegative = angleInDegrees < 0;
            angleInDegrees = Math.Abs(angleInDegrees);

            //gets the degree
            result.Degrees = (int)Math.Floor(angleInDegrees);
            var delta = angleInDegrees - result.Degrees;

            //gets minutes and seconds
            var seconds = (int)Math.Floor(3600.0 * delta);
            result.Seconds = seconds % 60;
            result.Minutes = (int)Math.Floor(seconds / 60.0);
            delta = delta * 3600.0 - seconds;

            //gets fractions
            result.Milliseconds = (int)(1000.0 * delta);

            return result;
        }
Example #2
0
        static void Main(string[] args)
        {
            var latdeg = 58;
            var latmin = 13;
            var latsec = 15;

            var londeg = 151;
            var lonmin = 11;
            var lonsec = 25;

            var coord = new GeoAngle();
            coord.Degrees = latdeg;
            coord.Minutes = latmin;
            coord.Seconds = latsec;

            var towerHeightFt = 80.0;
            var towerElevationFt = 2047.0;
            var totalFt = towerHeightFt + towerElevationFt;

            var elevM =  totalFt / 3.28084;

            var latdec = ConvertDMSToDouble(latdeg, latmin, latsec);
            Console.WriteLine(string.Format("Lat (decimal) {0:0.000000}",latdec));
            Console.WriteLine(string.Format("Lat (DMS) {0:0.000000}", GeoAngle.FromDouble(latdec)));

            var londec = ConvertDMSToDouble(londeg, lonmin, lonsec);
            Console.WriteLine(string.Format("Lon (decimal) {0:0.000000}", londec));
            Console.WriteLine(string.Format("Lon (DMS) {0:0.000000}", GeoAngle.FromDouble(londec)));

            Console.WriteLine(string.Format("Height (meters) {0:0.0}", elevM));

            Console.ReadLine();
        }