Exemplo n.º 1
0
        public static double ConvertDistanceToMeters(DistanceMeasurementType _fromType,
            double _fromValue)
        {
            double multiplier = 1.0;

            switch (_fromType)
            {
                case DistanceMeasurementType.Feet:
                {
                    multiplier = .3048;
                    break;
                }
                case DistanceMeasurementType.Kilometer:
                {
                    multiplier = 1000.0;
                    break;
                }
                case DistanceMeasurementType.Mile:
                {
                    multiplier = 1609.344;
                    break;
                }
                case DistanceMeasurementType.Meter:
                default:
                {
                    multiplier = 1.0;
                    break;
                }
            }

            return multiplier*_fromValue;
        }
Exemplo n.º 2
0
        public static double ConvertDistanceFromMeters(DistanceMeasurementType _toType,
            double _fromValue)
        {
            double multiplier = 1.0;

            switch (_toType)
            {
                case DistanceMeasurementType.Feet:
                {
                    multiplier = 3.2808399;
                    break;
                }
                case DistanceMeasurementType.Kilometer:
                {
                    multiplier = .001;
                    break;
                }
                case DistanceMeasurementType.Mile:
                {
                    multiplier = .000621371192;
                    break;
                }
                case DistanceMeasurementType.Meter:
                default:
                {
                    multiplier = 1.0;
                    break;
                }
            }

            return multiplier*_fromValue;
        }
Exemplo n.º 3
0
        public static double ConvertDistance(DistanceMeasurementType _fromType,
            DistanceMeasurementType _toType, double _fromValue)
        {
            if (_fromType == _toType)
            {
                return _fromValue;
            }

            double meterValue = ConvertDistanceToMeters(_fromType, _fromValue);
            return ConvertDistanceFromMeters(_toType, meterValue);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculate distance.
        /// </summary>
        /// <param name="longitude1">The longitude1.</param>
        /// <param name="latitude1">The latitude1.</param>
        /// <param name="longitude2">The longitude2.</param>
        /// <param name="latitude2">The latitude2.</param>
        /// <param name="measurement">The measurement.</param>
        public static double Distance(
            double longitude1,
            double latitude1,
            double longitude2,
            double latitude2,
            DistanceMeasurementType measurement = DistanceMeasurementType.Kilometers)
        {
            double diff     = longitude1 - longitude2;
            double distance = (System.Math.Sin(MathHelper.DegreesToRadians(latitude1)) * System.Math.Sin(MathHelper.DegreesToRadians(latitude2))) +
                              (System.Math.Cos(MathHelper.DegreesToRadians(latitude1)) * System.Math.Cos(MathHelper.DegreesToRadians(latitude2)) * System.Math.Cos(MathHelper.DegreesToRadians(diff)));

            distance = System.Math.Acos(distance);
            distance = MathHelper.RadiansToDegrees(distance);
            distance = distance * 60 * 1.1515;
            switch (measurement)
            {
            case DistanceMeasurementType.Meters:
                distance = distance * 1.609344 * 1000;
                break;

            case DistanceMeasurementType.Feet:
                distance = distance * 1.609344 * 1000 * 3.2808399;
                break;

            case DistanceMeasurementType.Kilometers:
                distance *= 1.609344;
                break;

            case DistanceMeasurementType.StatuteMiles:
                // default
                break;

            case DistanceMeasurementType.NauticalMiles:
                distance *= 0.8684;
                break;

            default:
                throw new SwitchCaseDefaultException(measurement);
            }

            return(distance);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Calculate distance.
 /// </summary>
 /// <param name="coordinate1">The coordinate1.</param>
 /// <param name="coordinate2">The coordinate2.</param>
 /// <param name="measurement">The measurement.</param>
 public static double Distance(
     CartesianCoordinate coordinate1,
     CartesianCoordinate coordinate2,
     DistanceMeasurementType measurement) =>
 Distance(coordinate1.Longitude, coordinate1.Latitude, coordinate2.Longitude, coordinate2.Latitude, measurement);
Exemplo n.º 6
0
        public void Distance(double expected, double latitude1, double longitude1, double latitude2, double longitude2, DistanceMeasurementType measurement)
        {
            // Act
            var actual = GeoSpatialHelper.Distance(latitude1, longitude1, latitude2, longitude2, measurement);

            // Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 7
0
        public void Distance_CartesianCoordinate(double expected, double latitude1, double longitude1, double latitude2, double longitude2, DistanceMeasurementType measurement)
        {
            // Arrange
            var coordinate1 = new CartesianCoordinate(latitude1, longitude1);
            var coordinate2 = new CartesianCoordinate(latitude2, longitude2);

            // Act
            var actual = GeoSpatialHelper.Distance(coordinate1, coordinate2, measurement);

            // Assert
            Assert.Equal(expected, actual);
        }