Ejemplo n.º 1
0
        public void ReverseGeoCode_RadialSearch_ReturnsMaxCountResults()
        {
            // Read a file with data with points in and around London in a 20Km radius
            var data       = GeoFileReader.ReadExtendedGeoNames(@"testdata\test_GB.txt").ToArray();
            var rg         = new ReverseGeoCode <ExtendedGeoName>(data);
            var center     = rg.CreateFromLatLong(51.5286416, 0); //Exactly at 0 longitude so we test left/right of prime meridian
            var maxresults = 10;

            Assert.AreEqual(47, data.Length);   //File should contain 47 records total

            var expected_ids = new[] { 2643741, 2646003, 2643743, 6690870, 2651621, 2655775, 2636503, 2634677, 2656194, 2653266 };

            Assert.AreEqual(maxresults, expected_ids.Length);

            // Search from the/a center in London for all points in a 10Km radius, allowing only maxresults results
            var searchresults = rg.RadialSearch(center, 100000.0, maxresults).ToArray();

            // Number of results should match length of expected_id array
            Assert.AreEqual(expected_ids.Length, searchresults.Length);
            // Check if each result is in the expected results array
            foreach (var r in searchresults)
            {
                Assert.IsTrue(expected_ids.Contains(r.Id));
            }
        }
Ejemplo n.º 2
0
        public void ReverseGeoCode_RadialSearch_ReturnsCorrectResults()
        {
            // Read a file with data with points in and around London in a 20Km radius
            var data = GeoFileReader.ReadExtendedGeoNames(@"testdata\test_GB.txt").ToArray();
            var rg = new ReverseGeoCode<ExtendedGeoName>(data);
            var center = rg.CreateFromLatLong(51.5286416, 0);   //Exactly at 0 longitude so we test left/right of prime meridian

            Assert.AreEqual(47, data.Length);   //File should contain 47 records total

            var expected_ids = new[] { 2640729, 2639577, 2642465, 2637627, 2633709, 2643339, 2634677, 2636503, 2652053, 2654710, 2643743, 2646003, 2643741, 2653941, 6690870, 2655775, 2651621, 2650497, 2656194, 2653266, 2648657, 2637433, 2652618, 2646057 };

            // Search from the/a center in London for all points in a 10Km radius
            var searchresults = rg.RadialSearch(center, 100000.0).ToArray();
            // Number of results should match length of expected_id array
            Assert.AreEqual(expected_ids.Length, searchresults.Length);
            // Check if each result is in the expected results array
            foreach (var r in searchresults)
                Assert.IsTrue(expected_ids.Contains(r.Id));
        }
Ejemplo n.º 3
0
 private void InitReverseGeoCode()
 {
     if (_reverseGeoCode != null)
     {
         return;
     }
     try
     {
         _reverseGeoCode = new ReverseGeoCode <ExtendedGeoName>(
             GeoFileReader.ReadExtendedGeoNames(
                 Path.Combine(_appSettings.TempFolder, GeoFileDownload.CountryName + ".txt")));
     }
     catch (ParserException e)
     {
         _logger?.LogError(e, "catch-ed GeoFileDownload GeoReverseLookup error");
     }
     catch (FileNotFoundException e)
     {
         _logger?.LogError(e, "catch-ed GeoFileDownload GeoReverseLookup error");
     }
 }
Ejemplo n.º 4
0
        public void ReverseGeoCode_NearestNeighbourSearch_ReturnsCorrectResults()
        {
            // Read a file with data with points in and around London in a 20Km radius
            var data   = GeoFileReader.ReadExtendedGeoNames(@"testdata\test_GB.txt").ToArray();
            var rg     = new ReverseGeoCode <ExtendedGeoName>(data);
            var center = rg.CreateFromLatLong(51.5286416, 0); //Exactly at 0 longitude so we test left/right of prime meridian

            Assert.AreEqual(47, data.Length);                 //File should contain 47 records total

            var expected_ids = new[] { 2640729, 2639577, 2642465, 2637627, 2633709, 2643339, 2634677, 2636503, 2652053, 2654710, 2643743, 2646003, 2643741, 2653941, 6690870, 2655775, 2651621, 2650497, 2656194, 2653266, 2648657, 2637433, 2652618, 2646057 };

            // Search from the/a center in London for the first X points (where X == expected_ids.length)
            var searchresults = rg.NearestNeighbourSearch(center, expected_ids.Length).ToArray();

            // Number of results should match length of expected_id array
            Assert.AreEqual(expected_ids.Length, searchresults.Length);
            // Check if each result is in the expected results array
            foreach (var r in searchresults)
            {
                Assert.IsTrue(expected_ids.Contains(r.Id));
            }
        }
Ejemplo n.º 5
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            MapControl = Map;
            if (e.NavigationMode == NavigationMode.Back)
            {
                ChangeViewControl.Map = Map;
            }
            var AllowOverstretch     = SettingsSetters.GetAllowOverstretch();
            var FadeAnimationEnabled = SettingsSetters.GetFadeAnimationEnabled();

            if (InternalHelper.InternetConnection())
            {
                ChangeViewControl.UseGoogleMaps(OnMapControls.ChangeViewUserControl.MapMode.Standard, AllowOverstretch: AllowOverstretch, IsFadingEnabled: FadeAnimationEnabled, ShowTraffic: SettingsSetters.GetShowTrafficOnLaunch());
            }
            else
            {
                Map.TileSources.Add(new MapTileSource(new LocalMapTileDataSource("ms-appdata:///local/MahMaps/mah_x_{x}-y_{y}-z_{zoomlevel}.jpeg"))
                {
                    AllowOverstretch = false, IsFadingEnabled = FadeAnimationEnabled
                });
            }
            inkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch;
            var drawingAttr = this.inkCanvas.InkPresenter.CopyDefaultDrawingAttributes();

            drawingAttr.PenTip         = PenTipShape.Rectangle;
            drawingAttr.Size           = new Size(4, 4);
            drawingAttr.IgnorePressure = true;
            drawingAttr.Color          = (Color)Resources["SystemControlBackgroundAccentBrush"];
            this.inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttr);
            if (e.Parameter != null)
            {
                //Google Maps Override
                if (e.Parameter.ToString().StartsWith("http"))
                {
                    //Search Uri association handler
                    if (((Uri)e.Parameter).Segments[2].ToLower() == "search/")
                    {
                        //Searchgrid.PopUP = true;
                        //Searchgrid.SearchText = ((Uri)e.Parameter).DecodeQueryParameters().Where(x => x.Key == "query").FirstOrDefault().Value;
                    }
                    //Directions Uri association handler
                    if (((Uri)e.Parameter).Segments[2].ToLower() == "dir/")
                    {
                        var parameters  = ((Uri)e.Parameter).DecodeQueryParameters();
                        var origin      = parameters.Where(x => x.Key == "origin").FirstOrDefault();
                        var destination = parameters.Where(x => x.Key == "destination").FirstOrDefault();
                        var travelmode  = parameters.Where(x => x.Key == "travelmode").FirstOrDefault();
                        var waypoints   = parameters.Where(x => x.Key == "waypoints").FirstOrDefault();
                        ViewModel.DirectionsControls.DirectionsHelper.DirectionModes Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.walking;
                        Geopoint OriginPoint        = null;
                        Geopoint DestinationPoint   = null;
                        List <BasicGeoposition> lst = null;
                        if (travelmode.Value != null)
                        {
                            if (travelmode.Value.ToString() == "driving")
                            {
                                Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.driving;
                            }
                            else if (travelmode.Value.ToString() == "bicycling ")
                            {
                                Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.bicycling;
                            }
                            else if (travelmode.Value.ToString() == "transit")
                            {
                                Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.transit;
                            }
                        }
                        if (origin.Value != null)
                        {
                            var latlng    = origin.Value.Split(',');
                            var Latitude  = Convert.ToDouble(latlng[0]);
                            var Longitude = Convert.ToDouble(latlng[1]);
                            OriginPoint = new Geopoint(new BasicGeoposition()
                            {
                                Latitude  = Latitude,
                                Longitude = Longitude
                            });
                        }
                        if (destination.Value != null)
                        {
                            var latlng    = destination.Value.Split(',');
                            var Latitude  = Convert.ToDouble(latlng[0]);
                            var Longitude = Convert.ToDouble(latlng[1]);
                            DestinationPoint = new Geopoint(new BasicGeoposition()
                            {
                                Latitude  = Latitude,
                                Longitude = Longitude
                            });
                        }
                        if (waypoints.Value != null)
                        {
                            lst = new List <BasicGeoposition>();
                            var latlngs = destination.Value.Split('|');
                            foreach (var item in latlngs)
                            {
                                var latlng             = item.Split(',');
                                BasicGeoposition point = new BasicGeoposition();
                                point.Latitude  = Convert.ToDouble(latlng[0]);
                                point.Longitude = Convert.ToDouble(latlng[1]);
                                lst.Add(point);
                            }
                        }
                        if (OriginPoint != null && DestinationPoint != null)
                        {
                            ViewModel.DirectionsControls.DirectionsHelper.Rootobject Result = null;
                            if (lst == null)
                            {
                                Result = await ViewModel.DirectionsControls.DirectionsHelper.GetDirections(OriginPoint.Position, DestinationPoint.Position, Mode);
                            }
                            else
                            {
                                Result = await ViewModel.DirectionsControls.DirectionsHelper.GetDirections(OriginPoint.Position, DestinationPoint.Position, Mode, lst);
                            }
                            if (Result != null)
                            {
                                Map.MapElements.Add(ViewModel.DirectionsControls.DirectionsHelper.GetDirectionAsRoute(Result, (Color)Resources["SystemControlBackgroundAccentBrush"]));
                            }
                        }
                    }
                    //Display a map
                    if (((Uri)e.Parameter).Segments[2].ToLower().StartsWith("@"))
                    {
                        await Task.Delay(1500);

                        try
                        {
                            if (!e.Parameter.ToString().Contains("searchplace"))
                            {
                                var parameters = ((Uri)e.Parameter).DecodeQueryParameters();
                                var mapaction  = parameters.Where(x => x.Key == "map_action").FirstOrDefault();
                                if (mapaction.Value != null && mapaction.Value == "pano")
                                {
                                    await new MessageDialog("StreetView Not Supported yet").ShowAsync();
                                }
                                var center = parameters.Where(x => x.Key == "center").FirstOrDefault();
                                var zoom   = parameters.Where(x => x.Key == "zoom").FirstOrDefault();
                                var cp     = center.Value.Split(',');
                                BasicGeoposition pointer = new BasicGeoposition()
                                {
                                    Latitude = Convert.ToDouble(cp[0]), Longitude = Convert.ToDouble(cp[1])
                                };
                                Map.Center = new Geopoint(pointer);
                                if (zoom.Value != null)
                                {
                                    await Map.TryZoomToAsync(Convert.ToDouble(zoom.Value));
                                }
                                RunMapRightTapped(Map, new Geopoint(pointer));
                            }
                            else
                            {
                                var search = ((Uri)e.Parameter).ToString().Replace("https://google.com/maps/@searchplace=", "");
                                //var search = parameters.Where(x => x.Key == "searchplace").FirstOrDefault();
                                var res = await ViewModel.PlaceControls.SearchHelper.TextSearch(search, Location : Map.Center, Radius : 15000);

                                if (res == null || res.results.Length == 0)
                                {
                                    await new MessageDialog("No search results found").ShowAsync();
                                    return;
                                }
                                var ploc     = res.results.FirstOrDefault().geometry.location;
                                var geopoint = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = ploc.lat, Longitude = ploc.lng
                                });
                                Map.Center = geopoint;
                                await MapView.MapControl.TryZoomToAsync(16);

                                SearchResultPoint = geopoint;
                            }
                        }
                        catch
                        {
                        }
                    }
                }

                //Windows Maps Override
                else
                {
                    var    parameters = ((Uri)e.Parameter).DecodeQueryParameters();
                    string cp         = "";
                    int    zoomlevel  = 0;
                    string Querry     = "";
                    string Where      = "";
                    //{bingmaps:?where=Tabarsi Square%2C north side of the Shrine%2C Mashhad%2C 2399%2C Īrān}
                    if (parameters.Where(x => x.Key == "where").Any())
                    {
                        Where = Uri.UnescapeDataString(parameters.Where(x => x.Key == "where").FirstOrDefault().Value.NoHTMLString());
                    }
                    if (parameters.Where(x => x.Key == "cp").Any())
                    {
                        cp = parameters.Where(x => x.Key == "cp").FirstOrDefault().Value;
                    }
                    if (parameters.Where(x => x.Key == "lvl").Any())
                    {
                        zoomlevel = Convert.ToInt32(parameters.Where(x => x.Key == "lvl").FirstOrDefault().Value);
                    }
                    if (parameters.Where(x => x.Key == "q").Any())
                    {
                        Querry = parameters.Where(x => x.Key == "q").FirstOrDefault().Value;
                    }
                    if (parameters.Where(x => x.Key == "collection").Any())
                    {
                        var point     = parameters.Where(x => x.Key == "collection").FirstOrDefault().Value;
                        var pointargs = point.Split('_');
                        var latitude  = pointargs[0].Split('.')[1] + "." + pointargs[0].Split('.')[2];
                        var longitude = pointargs[1];
                        cp = $"{latitude}~{longitude}";
                        if (parameters.Count >= 3)
                        {
                            Map.MapElements.Add(new MapIcon()
                            {
                                Location = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = Convert.ToDouble(latitude), Longitude = Convert.ToDouble(longitude)
                                }), Title = pointargs[2].Replace("+", " ")
                            });
                        }
                        else
                        {
                            Map.MapElements.Add(new MapIcon()
                            {
                                Location = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = Convert.ToDouble(latitude), Longitude = Convert.ToDouble(longitude)
                                }), Title = "Point"
                            });
                        }
                    }
                    if (Where != "")
                    {
                        await Task.Delay(500);

                        var res = await SearchHelper.TextSearch(Where);

                        if (res != null)
                        {
                            if (res.results != null && res.results.Any())
                            {
                                var loc = res.results.FirstOrDefault().geometry.location;
                                //var rgc = await ReverseGeoCode.GetLocation(Where);
                                Map.Center = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = loc.lat, Longitude = loc.lng
                                });
                            }
                            else
                            {
                                var rgc = await ReverseGeoCode.GetLocation(Where);

                                Map.Center = rgc;
                            }
                        }
                        else
                        {
                            var rgc = await ReverseGeoCode.GetLocation(Where);

                            Map.Center = rgc;
                        }
                    }
                    if (cp != "")
                    {
                        await Task.Delay(500);

                        var bgp = new BasicGeoposition();
                        bgp.Latitude  = Convert.ToDouble(cp.Split('~')[0]);
                        bgp.Longitude = Convert.ToDouble(cp.Split('~')[1]);
                        Map.Center    = new Geopoint(bgp);
                        Map.MapElements.Add(new MapIcon()
                        {
                            Location = new Geopoint(bgp), Title = "Point"
                        });
                    }
                    if (zoomlevel != 0)
                    {
                        await Map.TryZoomToAsync(zoomlevel);
                    }
                    else
                    {
                        await MapView.MapControl.TryZoomToAsync(16);
                    }
                    if (Querry != "")
                    {
                        await Task.Delay(1500);

                        Searchbar.SearchQuerry = Querry;
                    }
                }
            }

            if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush"))
            {
                var ac    = new Windows.UI.Xaml.Media.AcrylicBrush();
                var brush = Resources["SystemControlChromeLowAcrylicWindowBrush"] as Windows.UI.Xaml.Media.AcrylicBrush;
                ac                      = brush;
                ac.TintOpacity          = 0.8;
                ac.BackgroundSource     = Windows.UI.Xaml.Media.AcrylicBackgroundSource.HostBackdrop;
                InfoPane.PaneBackground = ac;
            }

            //MapViewVM.LoadPage();
        }
Ejemplo n.º 6
0
 public void Geonames_MultipleEntities()
 {
     var rgc1 = new ReverseGeoCode<Postalcode>();
     var rgc2 = new ReverseGeoCode<ExtendedGeoName>();
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            MRArguments argument = UsageChecker.checkAndBuildArgument(args);

            var r = new ReverseGeoCode <ExtendedGeoName>(GeoFileReader.ReadExtendedGeoNames(@argument.cityDbFileInfo.FullName));

            Parallel.ForEach(argument.targetDirs, (dir) => {
                if (dir.Name.Contains("@"))
                {
                    Console.WriteLine("skipping {0}.already renamed. maybe.. it`s name contains @ character", dir.Name);
                    return;
                }
                FileInfo[] files = dir.GetFiles();
                if (files != null && files.Length > 0)
                {
                    Dictionary <String, int> cCodeCounter = new Dictionary <String, int>();
                    Dictionary <String, int> cityCounter  = new Dictionary <String, int>();

                    foreach (FileInfo file in files)
                    {
                        try {
                            IEnumerable <MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(file.FullName);
                            GpsDirectory gpsDirectory = directories.OfType <GpsDirectory>().First();
                            if (gpsDirectory != null && gpsDirectory.GetGeoLocation() != null)
                            {
                                double lat             = gpsDirectory.GetGeoLocation().Latitude;
                                double lon             = gpsDirectory.GetGeoLocation().Longitude;
                                ExtendedGeoName result = r.NearestNeighbourSearch(r.CreateFromLatLong(lat, lon), 1).First();

                                String city = result.Name;
                                if (cityCounter.TryGetValue(city, out int tvalue))
                                {
                                    cityCounter[city] = tvalue + 1;
                                }
                                else
                                {
                                    cityCounter.Add(city, 1);
                                }
                                String ccode = result.CountryCode;
                                if (cCodeCounter.TryGetValue(ccode, out int cvalue))
                                {
                                    cCodeCounter[ccode] = cvalue + 1;
                                }
                                else
                                {
                                    cCodeCounter.Add(ccode, 1);
                                }
                            }
                        } catch (Exception) { }
                    }

                    if (cCodeCounter.Count > 0)
                    {
                        int total           = 0;
                        String countryName  = "";
                        int maxCountryCount = 0;
                        foreach (String key in cCodeCounter.Keys)
                        {
                            int tempCCount = cCodeCounter[key];
                            total         += tempCCount;
                            if (tempCCount > maxCountryCount)
                            {
                                countryName = key;
                            }
                        }
                        String cityName = "";
                        List <Tuple <String, int> > cities = new List <Tuple <String, int> >();
                        foreach (String key in cityCounter.Keys)
                        {
                            cities.Add(new Tuple <string, int>(key, cityCounter[key]));
                        }

                        Tuple <String, int>[] citiesArray = cities.OrderBy(tup => tup.Item2).ToArray();

                        String destination = dir.Name + " @" + countryName;

                        if (citiesArray != null && citiesArray.Length > 0)
                        {
                            destination += (", " + citiesArray[0].Item1);
                            cityName     = citiesArray[0].Item1;
                            if (citiesArray.Length > 1)
                            {
                                Console.WriteLine("second candidate citi name : {0}, count:{1}", citiesArray[1].Item1, citiesArray[1].Item2);
                                int c1val = citiesArray[0].Item2;
                                int c2val = citiesArray[1].Item2;
                                if (c2val / (float)c1val > 0.4)
                                {
                                    destination += ("," + citiesArray[1].Item1 + "... ");
                                }
                            }
                        }
                        bool moved = false;
                        try {
                            System.IO.Directory.Move(dir.FullName, dir.Parent.FullName + Path.DirectorySeparatorChar + destination);
                            moved = true;
                        } catch (Exception) { }

                        Console.WriteLine("{0} has {2}/{1} gps data and almost file located [{3}@{4}]. then renaming it to {5} : {6}", dir.Name, files.Length, total, cityName, countryName, destination, moved ? "success" : "failed");
                    }
                    else
                    {
                        Console.WriteLine("{0}`s {1} file has no gps data", dir.Name, files.Length);
                    }
                }
            });
        }
Ejemplo n.º 8
0
 public void Geonames_MultipleEntities()
 {
     var rgc1 = new ReverseGeoCode <Postalcode>();
     var rgc2 = new ReverseGeoCode <ExtendedGeoName>();
 }