Exemplo n.º 1
0
        public double CalculateDistance(GpsCoordinates location1, GpsCoordinates location2)
        {
            GeoCoordinate departure   = new GeoCoordinate(location1.Latitude, location1.Longitude);
            GeoCoordinate Destination = new GeoCoordinate(location2.Latitude, location2.Longitude);

            return(Math.Round(departure.DistanceTo(Destination, DistanceType.MILES), 2));
        }
        /// <summary>
        /// Calculates the distance between two sites
        /// </summary>
        /// <param name="firstSite">The first site</param>
        /// <param name="secondSite">The second site</param>
        /// <returns>The distance between the two sites in kilometers</returns>
        private static double GetDistance(Site firstSite, Site secondSite)
        {
            var firstLocation  = new GeoCoordinate(firstSite.Latitude, firstSite.Longitude);
            var secondLocation = new GeoCoordinate(secondSite.Latitude, secondSite.Longitude);

            return(firstLocation.DistanceTo(secondLocation, DistanceType.KILOMETERS));
        }
Exemplo n.º 3
0
        public void DistanceTest()
        {
            var Seattle = new GeoCoordinate(new Latitude(47.621800), new Longitude(-122.350326));
            var Olympia = new GeoCoordinate(new Latitude(47.041917), new Longitude(-122.893766));

            var Distance = Seattle.DistanceTo(Olympia);
            Assert.AreEqual(76.3866157995487, Distance, 0.0001);
        }
Exemplo n.º 4
0
        public void DistanceTest()
        {
            var Seattle = new GeoCoordinate(new Latitude(47.621800), new Longitude(-122.350326));
            var Olympia = new GeoCoordinate(new Latitude(47.041917), new Longitude(-122.893766));

            var Distance = Seattle.DistanceTo(Olympia);

            Assert.AreEqual(76.3866157995487, Distance, 0.0001);
        }
        public void DistanceTo_ReturnsZeroForSameCoordinate(long latitude, long longitude)
        {
            GeoCoordinate coordinate1 = new GeoCoordinate(latitude, longitude);
            GeoCoordinate coordinate2 = new GeoCoordinate(latitude, longitude);

            Distance actualDistance = coordinate1.DistanceTo(coordinate2);

            Distance expectedDistance = new Distance(0, GeoDistanceUnit.Meter);

            Assert.Equal(expectedDistance, actualDistance);
        }
Exemplo n.º 6
0
        public void HaversineDistance()
        {
            // ARRANGE
            GeoCoordinate Source      = new GeoCoordinate(40.7486, 5.4253);
            GeoCoordinate Destination = new GeoCoordinate(58.3838, 3.01412);

            // ACT
            double Distance = Source.DistanceTo(Destination, DistanceType.KILOMETERS);

            // ASSERT
            Assert.Equal(1967.0898177084771, Distance);
        }
Exemplo n.º 7
0
        void Model_UpdateStations()
        {
            var location = new GeoCoordinate(State_MyLa, State_MyLo);

            for (int index = 0; index < State_Stations.Count; index++)
            {
                var station = State_Stations[index];

                station.Station_Distance = location.DistanceTo(new GeoCoordinate(
                                                                   station.Station_La,
                                                                   station.Station_Lo
                                                                   ));
            }
        }
Exemplo n.º 8
0
        public PetResponseModel FindPetByName(PetModel pet)
        {
            var myLocation = new GeoCoordinate(52.0907, 5.1214);
            //GeoCoordinate Source = new GeoCoordinate(40.7486, 5.4253);
            //GeoCoordinate Destination = new GeoCoordinate(58.3838, 3.01412);
            //double Distance = myLocation.DistanceTo(pet.LastKnownLocation, DistanceType.KILOMETERS);

            var returnPet = new PetResponseModel()
            {
                Name            = pet.Name,
                CurrentLocation = pet.LastKnownLocation,
                Distance        = myLocation.DistanceTo(pet.LastKnownLocation, DistanceType.KILOMETERS),
            };

            return(returnPet);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Create line with geo coordinates.
        /// </summary>
        /// <param name="GeoCoordinate1">A geo coordinate.</param>
        /// <param name="GeoCoordinate2">A geo coordinate.</param>
        public GeoLine(GeoCoordinate GeoCoordinate1, GeoCoordinate GeoCoordinate2)
        {
            #region Initial Checks

            if (GeoCoordinate1   == null)
                throw new ArgumentNullException("The given left-coordinate must not be null!");

            if (GeoCoordinate2  == null)
                throw new ArgumentNullException("The given right-coordinate must not be null!");

            #endregion

            this.P1     = GeoCoordinate1;
            this.P2     = GeoCoordinate2;
            this.Length = GeoCoordinate1.DistanceTo(GeoCoordinate2);
            this.Tags   = new List<String>();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create a 2-dimensional vector of type T.
        /// </summary>
        /// <param name="GeoCoordinate1">A pixel of type T.</param>
        /// <param name="GeoCoordinate2">A pixel of type T.</param>
        public GeoVector(GeoCoordinate GeoCoordinate1, GeoCoordinate GeoCoordinate2)
        {
            #region Initial Checks

            if (GeoCoordinate1 == null)
                throw new ArgumentNullException("The first pixel must not be null!");

            if (GeoCoordinate2 == null)
                throw new ArgumentNullException("The second pixel must not be null!");

            #endregion

            this.P      = new GeoCoordinate(new Latitude (GeoCoordinate1.Latitude.Value  - GeoCoordinate2.Latitude.Value),
                                            new Longitude(GeoCoordinate1.Longitude.Value - GeoCoordinate2.Longitude.Value));

            this.Length = GeoCoordinate1.DistanceTo(GeoCoordinate2);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create line with geo coordinates.
        /// </summary>
        /// <param name="GeoCoordinate1">A geo coordinate.</param>
        /// <param name="GeoVector">A geo vector.</param>
        public GeoLine(GeoCoordinate GeoCoordinate1, GeoVector GeoVector)
        {
            #region Initial Checks

            if (GeoCoordinate1 == null)
                throw new ArgumentNullException("The given left-coordinate must not be null!");

            if (GeoVector == null)
                throw new ArgumentNullException("The given right-coordinate must not be null!");

            #endregion

            this.P1     = GeoCoordinate1;
            this.P2     = new GeoCoordinate(new Latitude (GeoCoordinate1.Latitude.Value  + GeoVector.P.Latitude.Value),
                                            new Longitude(GeoCoordinate1.Longitude.Value + GeoVector.P.Longitude.Value));

            this.Length = GeoCoordinate1.DistanceTo(P2);
            this.Tags   = new List<String>();
        }