Beispiel #1
0
        public IEnumerable GetSuggestions(string filter, object parameter)
        {
            IEnumerable <string> suggestions = this.GeoSuggester.SuggestAsync(filter).GetAwaiter().GetResult().Take(5);

            GeoObjectCollection objects = new GeoObjectCollection(suggestions.AsParallel().SelectMany(elem => this.Geocoder.GeocodeAsync(elem, 5).GetAwaiter().GetResult()));

            return(objects.Where(geo => geo.GeocoderMetaData.Kind == GeoObjectKind.Locality && !string.IsNullOrEmpty(geo.ToString())).Distinct().ToList().Distinct());
        }
        public IEnumerable GetSuggestions(string filter, object parameter)
        {
            GeoObject street = (GeoObject)parameter;

            IEnumerable <string> suggestions = this.GeoSuggester.SuggestAsync(this.BuildFilter(street, filter)).GetAwaiter().GetResult().Take(100);

            GeoObjectCollection objects = new GeoObjectCollection(suggestions.AsParallel().SelectMany(elem => this.Geocoder.GeocodeAsync(elem, 15).GetAwaiter().GetResult()));

            return(objects.Where(o => this.IsBuildingOnCity(o, street)).Distinct().ToList());
        }
Beispiel #3
0
        public static GeoPoint Coord(string str)
        {
            GeoObjectCollection results = YandexGeocoder.Geocode(str, 1, LangType.en_US);


            GeoPoint gh = new GeoPoint();

            foreach (GeoObject re in results)
            {
                gh = re.Point;
            }
            return(gh);
        }
Beispiel #4
0
        public static double ff(string str1, string str2)
        {
            GeoObjectCollection results  = YandexGeocoder.Geocode(str1, 1, LangType.en_US);
            GeoObjectCollection results1 = YandexGeocoder.Geocode(str2, 1, LangType.en_US);

            GeoPoint gh  = new GeoPoint();
            GeoPoint gh1 = new GeoPoint();

            foreach (GeoObject re in results)
            {
                gh = re.Point;
            }
            foreach (GeoObject re in results)
            {
                gh = re.Point;
            }
            foreach (GeoObject re in results1)
            {
                gh1 = re.Point;
            }

            if (gh.Lat == 0.0 || gh.Long == 0.0 || gh1.Lat == 0.0 || gh1.Long == 0.0)
            {
                MessageBox.Show("неправильно ввели город");
                Environment.Exit(0);
                return(0);
            }
            else
            {
                double pii    = Math.PI / 180;
                double lat1   = gh.Lat * pii;//gh.Lat*pii;
                double long1  = gh.Long * pii;
                double lat2   = gh1.Lat * pii;
                double long2  = gh1.Long * pii;
                double result = Math.Acos(Math.Sin(lat1) * Math.Sin(lat2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Cos(long1 - long2));

                double cl1    = Math.Cos(lat1);
                double cl2    = Math.Cos(lat2);
                double sl1    = Math.Sin(lat1);
                double sl2    = Math.Sin(lat2);
                double delta  = long2 - long1;
                double cdelta = Math.Cos(delta);
                double sdelta = Math.Sin(delta);
                double y      = Math.Sqrt(Math.Pow(cl2 * sdelta, 2) + Math.Pow(cl1 * sl2 - sl1 * cl2 * cdelta, 2));
                double x      = sl1 * sl2 + cl1 * cl2 * cdelta;
                double ad     = Math.Atan2(y, x);
                double dist   = ad * 6372795;

                return(result * 6371);
            }
        }
Beispiel #5
0
        public void UpdateLocation(GeoObjectCollection geoObjectCollection)
        {
            foreach (var geo in geoObjectCollection)
            {
                if (CheckLocation(geo.GeocoderMetaData.Text))
                {
                    _coordinatesCalculated = geo.Point;
                    continue;
                }

                var formattableString = $"{Program.KievPrefix}{this}\n{geo.GeocoderMetaData.Text}\n\n";
                File.AppendAllText("WrongStreet.txt", formattableString);
            }
        }
Beispiel #6
0
        private static void ProcessLine(string line, StreamWriter writer)
        {
            string[] chunks = line.Split(CSV_DELIMITER);

            if (IsLineValid(chunks))
            {
                string adress = chunks[6].Replace("г. ", "");
                string year   = chunks[7];

                GeoObjectCollection results = YandexGeocoder.Geocode(chunks[6], 1, LangType.ru_RU);
                if (results.Count() > 0)
                {
                    writer.WriteLine("{0},{1},{2},{3}", adress, year, results.First().Point.Lat, results.First().Point.Long);
                }
            }
        }
Beispiel #7
0
        public async Task <BuildingAddress> GetBuildingAsync(GeoPoint geoPoint)
        {
            GeoObjectCollection objectCollection =
                await this.Geocoder.ReverseGeocodeAsync(geoPoint, GeoObjectKind.House, 1, LangType.RU);

            GeoObject geoObject = objectCollection.First();
            Address   address   = geoObject.GeocoderMetaData.Address;

            int buildingId =
                await this.BuildingRepository.GetBuildingIdOrDefaultAsync(geoPoint.Latitude, geoPoint.Longitude);

            if (buildingId != default(int))
            {
                return(await this.BuildingRepository.GetBuildingAsync(buildingId));
            }

            int id = await this.PolyclinicRegionProvider.GetPolyclinicRegionIdAsync(address);

            PolyclinicRegion region = await this.PolyclinicRegionService.GetRegionAsync(id);

            BuildingAddress building = new BuildingAddress
            {
                City             = $"{address.Locality}, {address.Province}, {address.Country}",
                Street           = address.Street,
                Building         = address.House,
                Latitude         = geoPoint.Latitude,
                Longitude        = geoPoint.Longitude,
                PolyclinicRegion = region
            };

            int insertedBuildingId = await this.InsertOrUpdateBuildingAsync(building);

            building.Id = insertedBuildingId;

            return(building);
        }
        public IHttpActionResult PostGeoTag(GeoTag geotag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Address             address      = geotag.Address;
            string              placeAddress = string.Format("{0} {1} {2} {3}", address.City, address.Street, address.HouseNumber, address.Housing);
            GeoObjectCollection results      = YandexGeocoder.Geocode(placeAddress);

            foreach (GeoObject result in results)
            {
                geotag.Point      = new Point();
                geotag.Point.Lat  = result.Point.Lat;
                geotag.Point.Long = result.Point.Long;
                db.GeoTags.Add(geotag);
                db.SaveChanges();

                return(CreatedAtRoute("DefaultApi", new { id = geotag.Id }, geotag));
            }

            return(BadRequest());
        }