예제 #1
0
        public void GetDistanceTest()
        {
            var distance = GeoDistanceTo.GetDistance(51.6824134, 5.2984455, 51.6852471, 5.2943688);

            //      0.4222 km
            // https://www.movable-type.co.uk/scripts/latlong.html
            // https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula
            Assert.AreEqual(0.4223, distance, 0.001);
        }
예제 #2
0
        /// <summary>
        /// Reverse Geo Syncing for a folder
        /// </summary>
        /// <param name="metaFilesInDirectory">list of files to lookup</param>
        /// <param name="overwriteLocationNames">true = overwrite the location names, that have a gps location</param>
        /// <returns></returns>
        public List <FileIndexItem> LoopFolderLookup(List <FileIndexItem> metaFilesInDirectory,
                                                     bool overwriteLocationNames)
        {
            InitReverseGeoCode();

            metaFilesInDirectory = RemoveNoUpdateItems(metaFilesInDirectory, overwriteLocationNames);

            var subPath = metaFilesInDirectory.FirstOrDefault()?.ParentDirectory;

            new GeoCacheStatusService(_cache).StatusUpdate(subPath, metaFilesInDirectory.Count, StatusType.Total);

            foreach (var metaFileItem in metaFilesInDirectory.Select(
                         (value, index) => new { value, index }))
            {
                // Create a point from a lat/long pair from which we want to conduct our search(es) (center)
                var place = _reverseGeoCode.CreateFromLatLong(
                    metaFileItem.value.Latitude, metaFileItem.value.Longitude);

                // Find nearest
                var nearestPlace = _reverseGeoCode.NearestNeighbourSearch(place, 1).FirstOrDefault();

                // Distance to avoid non logic locations
                var distanceTo = GeoDistanceTo.GetDistance(
                    nearestPlace.Latitude,
                    nearestPlace.Longitude,
                    metaFileItem.value.Latitude,
                    metaFileItem.value.Longitude);

                new GeoCacheStatusService(_cache).StatusUpdate(metaFileItem.value.ParentDirectory,
                                                               metaFileItem.index, StatusType.Current);

                if (distanceTo > 35)
                {
                    continue;
                }
                // if less than 35 kilometers from that place add it to the object

                metaFileItem.value.LocationCity = nearestPlace.NameASCII;

                // Catch is used for example the region VA (Vatican City)
                try
                {
                    metaFileItem.value.LocationCountry = new RegionInfo(nearestPlace.CountryCode).NativeName;
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e);
                }
                metaFileItem.value.LocationState = GetAdmin1Name(nearestPlace.CountryCode, nearestPlace.Admincodes);
            }

            // Ready signal
            new GeoCacheStatusService(_cache).StatusUpdate(subPath,
                                                           metaFilesInDirectory.Count, StatusType.Current);

            return(metaFilesInDirectory);
        }
예제 #3
0
        public void GetDistanceTestLargeNumber()
        {
            var distance = GeoDistanceTo.GetDistance(-51.6824134, -5.2984455, 51.6852471, 5.2943688);

            Assert.AreEqual(11549.857139273592, distance, 0.001);
        }